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, #popolo
Instance Method Summary
collapse
Methods inherited from Entity
#==, #[], #identifier, #identifiers, #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
|
#honorific_prefix ⇒ Object
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_suffix ⇒ Object
Returns the value of attribute honorific_suffix.
8
9
10
|
# File 'lib/everypolitician/popolo/person.rb', line 8
def honorific_suffix
@honorific_suffix
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
22
23
24
|
# File 'lib/everypolitician/popolo/person.rb', line 22
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
38
39
40
|
# File 'lib/everypolitician/popolo/person.rb', line 38
def facebook
link('facebook')
end
|
#fax ⇒ Object
30
31
32
|
# File 'lib/everypolitician/popolo/person.rb', line 30
def fax
contact('fax')
end
|
#link(type) ⇒ Object
14
15
16
|
# File 'lib/everypolitician/popolo/person.rb', line 14
def link(type)
links.find(-> { {} }) { |i| i[:note] == type }[:url]
end
|
#links ⇒ Object
10
11
12
|
# File 'lib/everypolitician/popolo/person.rb', line 10
def links
document.fetch(:links, [])
end
|
#memberships ⇒ Object
62
63
64
|
# File 'lib/everypolitician/popolo/person.rb', line 62
def memberships
popolo.memberships.where(person_id: id)
end
|
#name_at(date) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/everypolitician/popolo/person.rb', line 50
def name_at(date)
return name unless key?(:other_names)
historic = other_names.select { |n| n.key?(:end_date) }
return name if historic.empty?
at_date = historic.select 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
26
27
28
|
# File 'lib/everypolitician/popolo/person.rb', line 26
def phone
contact('phone')
end
|
#sort_name ⇒ Object
46
47
48
|
# File 'lib/everypolitician/popolo/person.rb', line 46
def sort_name
name
end
|
34
35
36
|
# File 'lib/everypolitician/popolo/person.rb', line 34
def
contact('twitter') || link('twitter')
end
|
#wikidata ⇒ Object
42
43
44
|
# File 'lib/everypolitician/popolo/person.rb', line 42
def wikidata
identifier('wikidata')
end
|