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
Attributes inherited from Entity
#document, #popolo
Instance Method Summary
collapse
Methods inherited from Entity
#==, #[], classification, #id, #identifier, inherited, #initialize, #key?, subclasses, #wikidata
Instance Method Details
#birth_date ⇒ Object
30
31
32
|
# File 'lib/everypolitician/popolo/person.rb', line 30
def birth_date
document.fetch(:birth_date, nil)
end
|
58
59
60
|
# File 'lib/everypolitician/popolo/person.rb', line 58
def contact(type)
contact_details.find(-> { {} }) { |i| i[:type] == type }[:value]
end
|
54
55
56
|
# File 'lib/everypolitician/popolo/person.rb', line 54
def contact_details
document.fetch(:contact_details, [])
end
|
#death_date ⇒ Object
34
35
36
|
# File 'lib/everypolitician/popolo/person.rb', line 34
def death_date
document.fetch(:death_date, nil)
end
|
#email ⇒ Object
10
11
12
|
# File 'lib/everypolitician/popolo/person.rb', line 10
def email
document.fetch(:email, nil)
end
|
#facebook ⇒ Object
74
75
76
|
# File 'lib/everypolitician/popolo/person.rb', line 74
def facebook
link('facebook')
end
|
#family_name ⇒ Object
82
83
84
|
# File 'lib/everypolitician/popolo/person.rb', line 82
def family_name
document.fetch(:family_name, nil)
end
|
#fax ⇒ Object
66
67
68
|
# File 'lib/everypolitician/popolo/person.rb', line 66
def fax
contact('fax')
end
|
#gender ⇒ Object
18
19
20
|
# File 'lib/everypolitician/popolo/person.rb', line 18
def gender
document.fetch(:gender, nil)
end
|
#given_name ⇒ Object
86
87
88
|
# File 'lib/everypolitician/popolo/person.rb', line 86
def given_name
document.fetch(:given_name, nil)
end
|
#honorific_prefix ⇒ Object
38
39
40
|
# File 'lib/everypolitician/popolo/person.rb', line 38
def honorific_prefix
document.fetch(:honorific_prefix, nil)
end
|
#honorific_suffix ⇒ Object
42
43
44
|
# File 'lib/everypolitician/popolo/person.rb', line 42
def honorific_suffix
document.fetch(:honorific_suffix, nil)
end
|
#identifiers ⇒ Object
94
95
96
|
# File 'lib/everypolitician/popolo/person.rb', line 94
def identifiers
document.fetch(:identifiers, [])
end
|
#image ⇒ Object
14
15
16
|
# File 'lib/everypolitician/popolo/person.rb', line 14
def image
document.fetch(:image, nil)
end
|
#images ⇒ Object
98
99
100
|
# File 'lib/everypolitician/popolo/person.rb', line 98
def images
document.fetch(:images, [])
end
|
#link(type) ⇒ Object
50
51
52
|
# File 'lib/everypolitician/popolo/person.rb', line 50
def link(type)
links.find(-> { {} }) { |i| i[:note] == type }[:url]
end
|
#links ⇒ Object
46
47
48
|
# File 'lib/everypolitician/popolo/person.rb', line 46
def links
document.fetch(:links, [])
end
|
#memberships ⇒ Object
122
123
124
|
# File 'lib/everypolitician/popolo/person.rb', line 122
def memberships
popolo.memberships.where(person_id: id)
end
|
#name ⇒ Object
6
7
8
|
# File 'lib/everypolitician/popolo/person.rb', line 6
def name
document.fetch(:name, nil)
end
|
#name_at(date) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/everypolitician/popolo/person.rb', line 110
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
|
#national_identity ⇒ Object
22
23
24
|
# File 'lib/everypolitician/popolo/person.rb', line 22
def national_identity
document.fetch(:national_identity, nil)
end
|
#other_names ⇒ Object
102
103
104
|
# File 'lib/everypolitician/popolo/person.rb', line 102
def other_names
document.fetch(:other_names, [])
end
|
#patronymic_name ⇒ Object
90
91
92
|
# File 'lib/everypolitician/popolo/person.rb', line 90
def patronymic_name
document.fetch(:patronymic_name, nil)
end
|
#phone ⇒ Object
62
63
64
|
# File 'lib/everypolitician/popolo/person.rb', line 62
def phone
contact('phone')
end
|
#sort_name ⇒ Object
78
79
80
|
# File 'lib/everypolitician/popolo/person.rb', line 78
def sort_name
name
end
|
#sources ⇒ Object
106
107
108
|
# File 'lib/everypolitician/popolo/person.rb', line 106
def sources
document.fetch(:sources, [])
end
|
#summary ⇒ Object
26
27
28
|
# File 'lib/everypolitician/popolo/person.rb', line 26
def summary
document.fetch(:summary, nil)
end
|
70
71
72
|
# File 'lib/everypolitician/popolo/person.rb', line 70
def
contact('twitter') || link('twitter')
end
|