Files
nairobi/lib/local_census.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

65 lines
1.1 KiB
Ruby

include DocumentParser
class LocalCensus
def call(document_type, document_number)
record = nil
get_document_number_variants(document_type, document_number).each do |variant|
record = Response.new(get_record(document_type, variant))
return record if record.valid?
end
record
end
class Response
def initialize(body)
@body = body
end
def valid?
@body.present? ? !@body.attributes.values.include?("" || nil) : false
end
def date_of_birth
@body.date_of_birth
end
def postal_code
@body.postal_code
end
def district_code
@body.district_code
rescue
nil
end
def gender
case @body.gender
when "Varón"
"male"
when "Mujer"
"female"
end
rescue NoMethodError
nil
end
def name
"#{@body.nombre} #{@body.apellido1}"
rescue
nil
end
private
def data
@body.attributes
end
end
private
def get_record(document_type, document_number)
LocalCensusRecord.find_by(document_type: document_type, document_number: document_number)
end
end