Class: Pipl::API::Response::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/pipl/api/response/person.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Person

Returns a new instance of Person.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pipl/api/response/person.rb', line 15

def initialize(data)
  @name = Name.new(data["name"])
  @full_names = Name.new(data["full_names"]) unless data["full_names"] == {}
  @nicknames = Name.new(data["nicknames"]) unless data["nicknames"] == {}
  @spellings = Name.new(data["spellings"]) unless data["spellings"] == {}
  @translations = data["translations"] unless data["translations"] == {}
  @gender = Gender.new(data["gender"])
  @locations = data["top_locations"].map { |location| Location.new(location) }
  @ages = data["top_ages"].map { |age| Age.new(age) }
  @estimated_world_persons_count = data["estimated_world_persons_count"]
end

Instance Attribute Details

#agesObject (readonly)

Returns the value of attribute ages.



11
12
13
# File 'lib/pipl/api/response/person.rb', line 11

def ages
  @ages
end

#estimated_world_persons_countObject (readonly)

Returns the value of attribute estimated_world_persons_count.



13
14
15
# File 'lib/pipl/api/response/person.rb', line 13

def estimated_world_persons_count
  @estimated_world_persons_count
end

#full_namesObject (readonly)

Returns the value of attribute full_names.



6
7
8
# File 'lib/pipl/api/response/person.rb', line 6

def full_names
  @full_names
end

#genderObject (readonly)

Returns the value of attribute gender.



12
13
14
# File 'lib/pipl/api/response/person.rb', line 12

def gender
  @gender
end

#locationsObject (readonly)

Returns the value of attribute locations.



10
11
12
# File 'lib/pipl/api/response/person.rb', line 10

def locations
  @locations
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/pipl/api/response/person.rb', line 5

def name
  @name
end

#nicknamesObject (readonly)

Returns the value of attribute nicknames.



7
8
9
# File 'lib/pipl/api/response/person.rb', line 7

def nicknames
  @nicknames
end

#spellingsObject (readonly)

Returns the value of attribute spellings.



8
9
10
# File 'lib/pipl/api/response/person.rb', line 8

def spellings
  @spellings
end

#translationsObject (readonly)

Returns the value of attribute translations.



9
10
11
# File 'lib/pipl/api/response/person.rb', line 9

def translations
  @translations
end

Instance Method Details

#to_hashObject Also known as: to_h



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pipl/api/response/person.rb', line 27

def to_hash
  [
    :name, :full_names, :nicknames,
    :spellings, :translations, :gender,
    :locations, :ages, :estimated_world_persons_count
  ].each do |accessor|
    value = case send(accessor)
      when Array then send(accessor).map(&:to_hash) if send(accessor).any?
      when Integer then send(accessor) if send(accessor)
      else send(accessor).to_hash if send(accessor)
    end
    { accessor => value }
  end.inject(&:merge!)
end