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, inherited, #initialize, #key?, subclasses, #wikidata

Constructor Details

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

Instance Method Details

#birth_dateObject



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

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

#contact(type) ⇒ Object



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

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

#contact_detailsObject



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

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

#death_dateObject



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

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

#emailObject



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

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

#facebookObject



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

def facebook
  link('facebook')
end

#family_nameObject



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

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

#faxObject



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

def fax
  contact('fax')
end

#genderObject



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

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

#given_nameObject



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

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

#honorific_prefixObject



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

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

#honorific_suffixObject



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

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

#identifiersObject



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

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

#imageObject



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

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

#imagesObject



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

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


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

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


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

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

#membershipsObject



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

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

#nameObject



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_identityObject



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

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

#other_namesObject



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

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

#patronymic_nameObject



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

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

#phoneObject



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

def phone
  contact('phone')
end

#sort_nameObject



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

def sort_name
  name
end

#sourcesObject



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

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

#summaryObject



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

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

#twitterObject



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

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