Class: Everypolitician::Popolo::Person

Inherits:
Entity
  • Object
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, #identifiers, inherited, #initialize, #key?, subclasses, #wikidata

Constructor Details

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

Instance Method Details

#birth_dateObject


35
36
37
# File 'lib/everypolitician/popolo/person.rb', line 35

def birth_date
  document.fetch(:birth_date, nil)
end

#contact(type) ⇒ Object


63
64
65
# File 'lib/everypolitician/popolo/person.rb', line 63

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

#contact_detailsObject


59
60
61
# File 'lib/everypolitician/popolo/person.rb', line 59

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

#death_dateObject


39
40
41
# File 'lib/everypolitician/popolo/person.rb', line 39

def death_date
  document.fetch(:death_date, nil)
end

#emailObject


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

def email
  document.fetch(:email, nil)
end

#facebookObject


79
80
81
# File 'lib/everypolitician/popolo/person.rb', line 79

def facebook
  link('facebook')
end

#family_nameObject


87
88
89
# File 'lib/everypolitician/popolo/person.rb', line 87

def family_name
  document.fetch(:family_name, nil)
end

#faxObject


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

def fax
  contact('fax')
end

#genderObject


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

def gender
  document.fetch(:gender, nil)
end

#given_nameObject


91
92
93
# File 'lib/everypolitician/popolo/person.rb', line 91

def given_name
  document.fetch(:given_name, nil)
end

#honorific_prefixObject


43
44
45
# File 'lib/everypolitician/popolo/person.rb', line 43

def honorific_prefix
  document.fetch(:honorific_prefix, nil)
end

#honorific_suffixObject


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

def honorific_suffix
  document.fetch(:honorific_suffix, nil)
end

#imageObject


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

def image
  document.fetch(:image, nil)
end

#imagesObject


99
100
101
# File 'lib/everypolitician/popolo/person.rb', line 99

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

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

def link(type)
  links.find(-> { {} }) { |i| i[:note] == type }[:url]
end

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

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

#membershipsObject


123
124
125
# File 'lib/everypolitician/popolo/person.rb', line 123

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

#nameObject


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

def name
  document.fetch(:name, nil)
end

#name_at(date) ⇒ Object


111
112
113
114
115
116
117
118
119
120
121
# File 'lib/everypolitician/popolo/person.rb', line 111

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_identityObject


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

def national_identity
  document.fetch(:national_identity, nil)
end

#other_namesObject


103
104
105
# File 'lib/everypolitician/popolo/person.rb', line 103

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

#patronymic_nameObject


95
96
97
# File 'lib/everypolitician/popolo/person.rb', line 95

def patronymic_name
  document.fetch(:patronymic_name, nil)
end

#phoneObject


67
68
69
# File 'lib/everypolitician/popolo/person.rb', line 67

def phone
  contact('phone')
end

#sort_nameObject


83
84
85
# File 'lib/everypolitician/popolo/person.rb', line 83

def sort_name
  name
end

#sourcesObject


107
108
109
# File 'lib/everypolitician/popolo/person.rb', line 107

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

#summaryObject


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

def summary
  document.fetch(:summary, nil)
end

#twitterObject


75
76
77
# File 'lib/everypolitician/popolo/person.rb', line 75

def twitter
  contact('twitter') || link('twitter')
end