Class: Everypolitician::Popolo::Person
- Inherits:
-
Entity
- Object
- Entity
- Everypolitician::Popolo::Person
show all
- Defined in:
- lib/everypolitician/popolo/person.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
Attributes inherited from Entity
#document, #id
Instance Method Summary
collapse
Methods inherited from Entity
#==, #[], #initialize, #key?
Instance Attribute Details
#birth_date ⇒ Object
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_date ⇒ Object
Returns the value of attribute death_date.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def death_date
@death_date
end
|
#email ⇒ Object
Returns the value of attribute email.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def email
@email
end
|
#gender ⇒ Object
Returns the value of attribute gender.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def gender
@gender
end
|
#image ⇒ Object
Returns the value of attribute image.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def image
@image
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def name
@name
end
|
Instance Method Details
27
28
29
|
# File 'lib/everypolitician/popolo/person.rb', line 27
def contact(type)
contact_details.find(->{{}}) { |i| i[:type] == type }[:value]
end
|
18
19
20
|
# File 'lib/everypolitician/popolo/person.rb', line 18
def contact_details
document.fetch(:contact_details, [])
end
|
#facebook ⇒ Object
52
53
54
55
|
# File 'lib/everypolitician/popolo/person.rb', line 52
def facebook
facebook_link = links.find { |d| d[:note] == 'facebook' }
facebook_link[:url] if facebook_link
end
|
#fax ⇒ Object
35
36
37
|
# File 'lib/everypolitician/popolo/person.rb', line 35
def fax
contact('fax')
end
|
#identifier(scheme) ⇒ Object
23
24
25
|
# File 'lib/everypolitician/popolo/person.rb', line 23
def identifier(scheme)
identifiers.find(->{{}}) { |i| i[:scheme] == scheme }[:identifier]
end
|
#identifiers ⇒ Object
14
15
16
|
# File 'lib/everypolitician/popolo/person.rb', line 14
def identifiers
document.fetch(:identifiers, [])
end
|
#links ⇒ Object
10
11
12
|
# File 'lib/everypolitician/popolo/person.rb', line 10
def links
document.fetch(:links, [])
end
|
#name_at(date) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/everypolitician/popolo/person.rb', line 65
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
|
#phone ⇒ Object
31
32
33
|
# File 'lib/everypolitician/popolo/person.rb', line 31
def phone
contact('phone')
end
|
#sort_name ⇒ Object
61
62
63
|
# File 'lib/everypolitician/popolo/person.rb', line 61
def sort_name
name
end
|
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/everypolitician/popolo/person.rb', line 39
def
if key?(:contact_details)
if = self[:contact_details].find { |d| d[:type] == 'twitter' }
return [:value].strip
end
end
if key?(:links)
if = self[:links].find { |d| d[:note][/twitter/i] }
return [:url].strip
end
end
end
|
#wikidata ⇒ Object
57
58
59
|
# File 'lib/everypolitician/popolo/person.rb', line 57
def wikidata
identifier('wikidata')
end
|