Class: Everypolitician::Popolo::Person

Inherits:
Entity
  • Object
show all
Defined in:
lib/everypolitician/popolo/person.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Entity

#document, #id, #popolo

Instance Method Summary collapse

Methods inherited from Entity

#==, #[], #identifier, #initialize, #key?

Constructor Details

This class inherits a constructor from Everypolitician::Popolo::Entity

Instance Attribute Details

#birth_dateObject

Returns the value of attribute birth_date.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def birth_date
  @birth_date
end

#death_dateObject

Returns the value of attribute death_date.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def death_date
  @death_date
end

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def email
  @email
end

#genderObject

Returns the value of attribute gender.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def gender
  @gender
end

#honorific_prefixObject

Returns the value of attribute honorific_prefix.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def honorific_prefix
  @honorific_prefix
end

#honorific_suffixObject

Returns the value of attribute honorific_suffix.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def honorific_suffix
  @honorific_suffix
end

#imageObject

Returns the value of attribute image.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def image
  @image
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/everypolitician/popolo/person.rb', line 8

def name
  @name
end

Instance Method Details

#contact(type) ⇒ Object



22
23
24
# File 'lib/everypolitician/popolo/person.rb', line 22

def contact(type)
  contact_details.find(->{{}}) { |i| i[:type] == type }[:value]
end

#contact_detailsObject



18
19
20
# File 'lib/everypolitician/popolo/person.rb', line 18

def contact_details
  document.fetch(:contact_details, [])
end

#facebookObject



47
48
49
50
# File 'lib/everypolitician/popolo/person.rb', line 47

def facebook
  facebook_link = links.find { |d| d[:note] == 'facebook' }
  facebook_link[:url] if facebook_link
end

#faxObject



30
31
32
# File 'lib/everypolitician/popolo/person.rb', line 30

def fax
  contact('fax')
end

#identifiersObject



14
15
16
# File 'lib/everypolitician/popolo/person.rb', line 14

def identifiers
  document.fetch(:identifiers, [])
end


10
11
12
# File 'lib/everypolitician/popolo/person.rb', line 10

def links
  document.fetch(:links, [])
end

#membershipsObject



72
73
74
# File 'lib/everypolitician/popolo/person.rb', line 72

def memberships
  popolo.memberships.where(person_id: id)
end

#name_at(date) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/everypolitician/popolo/person.rb', line 60

def name_at(date)
  return name unless key?(:other_names)
  historic = other_names.find_all { |n| n.key?(:end_date) }
  return name if historic.empty?
  at_date = historic.find_all do |n|
    n[:end_date] >= date && (n[:start_date] || '0000-00-00') <= date
  end
  return name if at_date.empty?
  fail Error, "Too many names at #{date}: #{at_date}" if at_date.count > 1
  at_date.first[:name]
end

#phoneObject



26
27
28
# File 'lib/everypolitician/popolo/person.rb', line 26

def phone
  contact('phone')
end

#sort_nameObject



56
57
58
# File 'lib/everypolitician/popolo/person.rb', line 56

def sort_name
  name
end

#twitterObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/everypolitician/popolo/person.rb', line 34

def twitter
  if key?(:contact_details)
    if twitter_contact = self[:contact_details].find { |d| d[:type] == 'twitter' }
      return twitter_contact[:value].strip
    end
  end
  if key?(:links)
    if twitter_link = self[:links].find { |d| d[:note][/twitter/i] }
      return twitter_link[:url].strip
    end
  end
end

#wikidataObject



52
53
54
# File 'lib/everypolitician/popolo/person.rb', line 52

def wikidata
  identifier('wikidata')
end