Module: Parliament::Grom::Decorator::Person
- Includes:
- Helpers::DateHelper
- Defined in:
- lib/parliament/grom/decorator/person.rb
Overview
Decorator namespace for Grom::Node instances with type: id.parliament.uk/schema/Person.
Instance Method Summary collapse
-
#alternate? ⇒ Boolean
Check whether member is an alternate?.
-
#constituencies ⇒ Array
Alias houseSeatHasConstituencyGroup with fallback.
-
#contact_points ⇒ Array
Alias personHasContactPoint with fallback.
-
#current_lord? ⇒ Boolean
Check whether they have a current seat on the House of Lords.
-
#current_mp? ⇒ Boolean
Check whether they have a current seat on the House of Commons.
-
#current_party ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
-
#current_party_membership ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
-
#current_seat_incumbency ⇒ Grom::Node
The seat incumbency as a Grom::Node or nil.
-
#date_of_birth ⇒ DateTime?
Alias personDateOfBirth with fallback.
-
#display_name ⇒ String
Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
-
#ex_officio? ⇒ Boolean
Check whether member is an ex_officio?.
-
#facebook_weblinks ⇒ Array
Alias personHasFacebookWebLink with fallback.
-
#family_name ⇒ String
Alias personFamilyName with fallback.
-
#formal_body_memberships ⇒ Array
Alias memberHasFormalBodyMembership with fallback.
-
#former_lord? ⇒ Boolean
Check whether they are a former member of the House of Lords.
-
#former_mp? ⇒ Boolean
Check whether they are a former member of the House of Commons.
-
#full_name ⇒ String
Builds a full name using personGivenName and personFamilyName.
-
#full_title ⇒ String
Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.
-
#gender ⇒ Array
Alias genderIdentityHasGender with fallback.
-
#gender_identities ⇒ Array
Alias personHasGenderIdentity with fallback.
-
#given_name ⇒ String
Alias personGivenName with fallback.
-
#government_incumbencies ⇒ Array
Alias governmentIncumbency with fallback.
-
#houses ⇒ Array
Alias houseSeatHasHouse with fallback.
-
#image_id(show_placeholder: true) ⇒ String
Alias personHasPersonImage with fallback.
-
#incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
-
#lay_member? ⇒ Boolean
Check whether person is a lay member?.
-
#mnis_id ⇒ Array
Alias memberMnisId with fallback.
-
#most_recent_seat_incumbency ⇒ Grom::Node
The most recent seat incumbency as a Grom::Node or nil.
-
#other_name ⇒ String
Alias personOtherNames with fallback.
-
#parties ⇒ Array
Alias partyMembershipHasParty with fallback.
-
#party_memberships ⇒ Array
Alias partyMemberHasPartyMembership with fallback.
-
#person_type ⇒ String
Check whether they are a Member or a Lord from their latest seat incumbency.
-
#personal_weblinks ⇒ Array
Alias personHasPersonalWebLink with fallback.
-
#pims_id ⇒ Array
Alias personPimsId with fallback.
-
#seat_incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
-
#seats ⇒ Array
Alias seatIncumbencyHasHouseSeat with fallback.
-
#sort_name ⇒ String
Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.
-
#statuses ⇒ Hash
Checks the statuses of the Grom::Node.
-
#twitter_weblinks ⇒ Array
Alias personHasTwitterWebLink with fallback.
-
#weblinks? ⇒ Boolean
Check whether a person has any weblinks.
Methods included from Helpers::DateHelper
Instance Method Details
#alternate? ⇒ Boolean
Check whether member is an alternate?.
212 213 214 |
# File 'lib/parliament/grom/decorator/person.rb', line 212 def alternate? respond_to?(:memberHasAlternateMembership) end |
#constituencies ⇒ Array
Alias houseSeatHasConstituencyGroup with fallback.
115 116 117 |
# File 'lib/parliament/grom/decorator/person.rb', line 115 def constituencies @constituencies ||= seats.map(&:constituency).flatten.uniq.compact end |
#contact_points ⇒ Array
Alias personHasContactPoint with fallback.
150 151 152 |
# File 'lib/parliament/grom/decorator/person.rb', line 150 def contact_points respond_to?(:personHasContactPoint) ? personHasContactPoint : [] end |
#current_lord? ⇒ Boolean
Check whether they have a current seat on the House of Lords.
198 199 200 |
# File 'lib/parliament/grom/decorator/person.rb', line 198 def current_lord? current_member_by_house?('House of Lords') end |
#current_mp? ⇒ Boolean
Check whether they have a current seat on the House of Commons.
184 185 186 |
# File 'lib/parliament/grom/decorator/person.rb', line 184 def current_mp? current_member_by_house?('House of Commons') end |
#current_party ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
136 137 138 |
# File 'lib/parliament/grom/decorator/person.rb', line 136 def current_party @current_party ||= party_memberships.select(&:current?).select(&:party)&.first&.party end |
#current_party_membership ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
143 144 145 |
# File 'lib/parliament/grom/decorator/person.rb', line 143 def current_party_membership @current_party_membership ||= party_memberships.select(&:current?).select(&:party)&.first end |
#current_seat_incumbency ⇒ Grom::Node
Returns the seat incumbency as a Grom::Node or nil.
89 90 91 |
# File 'lib/parliament/grom/decorator/person.rb', line 89 def current_seat_incumbency @current_seat_incumbency ||= seat_incumbencies.select(&:current?)&.first end |
#date_of_birth ⇒ DateTime?
Alias personDateOfBirth with fallback.
32 33 34 |
# File 'lib/parliament/grom/decorator/person.rb', line 32 def date_of_birth @date_of_birth ||= respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil end |
#display_name ⇒ String
Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
252 253 254 |
# File 'lib/parliament/grom/decorator/person.rb', line 252 def display_name respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name end |
#ex_officio? ⇒ Boolean
Check whether member is an ex_officio?.
205 206 207 |
# File 'lib/parliament/grom/decorator/person.rb', line 205 def ex_officio? respond_to?(:memberHasExOfficioMembership) end |
#facebook_weblinks ⇒ Array
Alias personHasFacebookWebLink with fallback.
294 295 296 |
# File 'lib/parliament/grom/decorator/person.rb', line 294 def facebook_weblinks [*get_weblinks_by_predicate(:personHasFacebookWebLink)] end |
#family_name ⇒ String
Alias personFamilyName with fallback.
18 19 20 |
# File 'lib/parliament/grom/decorator/person.rb', line 18 def family_name respond_to?(:personFamilyName) ? personFamilyName : '' end |
#formal_body_memberships ⇒ Array
Alias memberHasFormalBodyMembership with fallback.
266 267 268 |
# File 'lib/parliament/grom/decorator/person.rb', line 266 def formal_body_memberships respond_to?(:memberHasFormalBodyMembership) ? memberHasFormalBodyMembership : [] end |
#former_lord? ⇒ Boolean
Check whether they are a former member of the House of Lords.
226 227 228 |
# File 'lib/parliament/grom/decorator/person.rb', line 226 def former_lord? former_member_by_house?('House of Lords') end |
#former_mp? ⇒ Boolean
Check whether they are a former member of the House of Commons.
191 192 193 |
# File 'lib/parliament/grom/decorator/person.rb', line 191 def former_mp? former_member_by_house?('House of Commons') end |
#full_name ⇒ String
Builds a full name using personGivenName and personFamilyName.
39 40 41 42 43 44 45 46 47 |
# File 'lib/parliament/grom/decorator/person.rb', line 39 def full_name return @full_name unless @full_name.nil? full_name = [] full_name << personGivenName if respond_to?(:personGivenName) full_name << personFamilyName if respond_to?(:personFamilyName) @full_name = full_name.join(' ') end |
#full_title ⇒ String
Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.
245 246 247 |
# File 'lib/parliament/grom/decorator/person.rb', line 245 def full_title respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : '' end |
#gender ⇒ Array
Alias genderIdentityHasGender with fallback.
164 165 166 |
# File 'lib/parliament/grom/decorator/person.rb', line 164 def gender gender_identities.empty? ? nil : gender_identities.first.gender end |
#gender_identities ⇒ Array
Alias personHasGenderIdentity with fallback.
157 158 159 |
# File 'lib/parliament/grom/decorator/person.rb', line 157 def gender_identities respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : [] end |
#given_name ⇒ String
Alias personGivenName with fallback.
11 12 13 |
# File 'lib/parliament/grom/decorator/person.rb', line 11 def given_name respond_to?(:personGivenName) ? personGivenName : '' end |
#government_incumbencies ⇒ Array
Alias governmentIncumbency with fallback.
273 274 275 |
# File 'lib/parliament/grom/decorator/person.rb', line 273 def government_incumbencies respond_to?(:governmentIncumbency) ? governmentIncumbency : [] end |
#houses ⇒ Array
Alias houseSeatHasHouse with fallback.
108 109 110 |
# File 'lib/parliament/grom/decorator/person.rb', line 108 def houses @houses ||= [seats.map(&:house), seat_incumbencies.map(&:house)].flatten.uniq.compact end |
#image_id(show_placeholder: true) ⇒ String
Alias personHasPersonImage with fallback.
52 53 54 55 56 57 58 |
# File 'lib/parliament/grom/decorator/person.rb', line 52 def image_id(show_placeholder: true) if respond_to?(:memberHasMemberImage) memberHasMemberImage.first.graph_id else show_placeholder ? 'placeholder' : nil end end |
#incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
77 78 79 |
# File 'lib/parliament/grom/decorator/person.rb', line 77 def incumbencies respond_to?(:memberHasParliamentaryIncumbency) ? memberHasParliamentaryIncumbency : [] end |
#lay_member? ⇒ Boolean
Check whether person is a lay member?.
219 220 221 |
# File 'lib/parliament/grom/decorator/person.rb', line 219 def lay_member? respond_to?(:formalBodyLayPersonMnisId) end |
#mnis_id ⇒ Array
Alias memberMnisId with fallback.
70 71 72 |
# File 'lib/parliament/grom/decorator/person.rb', line 70 def mnis_id respond_to?(:memberMnisId) ? memberMnisId : nil end |
#most_recent_seat_incumbency ⇒ Grom::Node
Returns the most recent seat incumbency as a Grom::Node or nil.
94 95 96 |
# File 'lib/parliament/grom/decorator/person.rb', line 94 def most_recent_seat_incumbency @most_recent_seat_incumbency ||= seat_incumbencies.sort_by!(&:start_date).reverse.first end |
#other_name ⇒ String
Alias personOtherNames with fallback.
25 26 27 |
# File 'lib/parliament/grom/decorator/person.rb', line 25 def other_name respond_to?(:personOtherNames) ? personOtherNames : '' end |
#parties ⇒ Array
Alias partyMembershipHasParty with fallback.
129 130 131 |
# File 'lib/parliament/grom/decorator/person.rb', line 129 def parties @parties ||= party_memberships.map(&:party).flatten.uniq.compact end |
#party_memberships ⇒ Array
Alias partyMemberHasPartyMembership with fallback.
122 123 124 |
# File 'lib/parliament/grom/decorator/person.rb', line 122 def party_memberships respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : [] end |
#person_type ⇒ String
Check whether they are a Member or a Lord from their latest seat incumbency. Current incumbencies are higher priority when determining a person_type Therefore check first for former, then current
234 235 236 237 238 239 240 |
# File 'lib/parliament/grom/decorator/person.rb', line 234 def person_type person_type = 'member' if former_mp? person_type = 'lord' if former_lord? person_type = 'member' if current_mp? person_type = 'lord' if current_lord? person_type end |
#personal_weblinks ⇒ Array
Alias personHasPersonalWebLink with fallback.
280 281 282 |
# File 'lib/parliament/grom/decorator/person.rb', line 280 def personal_weblinks [*get_weblinks_by_predicate(:personHasPersonalWebLink)] end |
#pims_id ⇒ Array
Alias personPimsId with fallback.
63 64 65 |
# File 'lib/parliament/grom/decorator/person.rb', line 63 def pims_id respond_to?(:personPimsId) ? personPimsId : nil end |
#seat_incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
84 85 86 |
# File 'lib/parliament/grom/decorator/person.rb', line 84 def seat_incumbencies @seat_incumbencies ||= incumbencies.select { |inc| inc.type == 'https://id.parliament.uk/schema/SeatIncumbency' } end |
#seats ⇒ Array
Alias seatIncumbencyHasHouseSeat with fallback.
101 102 103 |
# File 'lib/parliament/grom/decorator/person.rb', line 101 def seats @seats ||= seat_incumbencies.map(&:seat).flatten.uniq.compact end |
#sort_name ⇒ String
Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.
259 260 261 |
# File 'lib/parliament/grom/decorator/person.rb', line 259 def sort_name respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : '' end |
#statuses ⇒ Hash
Checks the statuses of the Grom::Node.
171 172 173 174 175 176 177 178 179 |
# File 'lib/parliament/grom/decorator/person.rb', line 171 def statuses return @statuses unless @statuses.nil? statuses = {} statuses[:house_membership_status] = house_membership_status statuses[:general_membership_status] = general_membership_status @statuses = statuses end |
#twitter_weblinks ⇒ Array
Alias personHasTwitterWebLink with fallback.
287 288 289 |
# File 'lib/parliament/grom/decorator/person.rb', line 287 def twitter_weblinks [*get_weblinks_by_predicate(:personHasTwitterWebLink)] end |
#weblinks? ⇒ Boolean
Check whether a person has any weblinks
299 300 301 |
# File 'lib/parliament/grom/decorator/person.rb', line 299 def weblinks? (personal_weblinks + twitter_weblinks + facebook_weblinks).any? end |