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?.
- #committee_membership_type ⇒ Object
-
#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 personHasFormalBodyMembership 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.
-
#gender_pronoun ⇒ String
Gets the gender pronoun of the Grom::Node.
-
#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?.
222 223 224 |
# File 'lib/parliament/grom/decorator/person.rb', line 222 def alternate? respond_to?(:memberHasAlternateMembership) end |
#committee_membership_type ⇒ Object
233 234 235 236 237 238 239 240 |
# File 'lib/parliament/grom/decorator/person.rb', line 233 def committee_membership_type committee_membership_type = [] committee_membership_type << I18n.t('person.committee.lay') if lay_member? committee_membership_type << I18n.t('person.committee.ex_officio') if ex_officio? committee_membership_type << I18n.t('person.committee.alternate') if alternate? committee_membership_type << I18n.t('person.committee.member') committee_membership_type end |
#constituencies ⇒ Array
Alias houseSeatHasConstituencyGroup with fallback.
114 115 116 |
# File 'lib/parliament/grom/decorator/person.rb', line 114 def constituencies @constituencies ||= seats.map(&:constituency).flatten.uniq.compact end |
#contact_points ⇒ Array
Alias personHasContactPoint with fallback.
149 150 151 |
# File 'lib/parliament/grom/decorator/person.rb', line 149 def contact_points respond_to?(:personHasContactPoint) ? personHasContactPoint : [] end |
#current_lord? ⇒ Boolean
Check whether they have a current seat on the House of Lords.
208 209 210 |
# File 'lib/parliament/grom/decorator/person.rb', line 208 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.
194 195 196 |
# File 'lib/parliament/grom/decorator/person.rb', line 194 def current_mp? current_member_by_house?('House of Commons') end |
#current_party ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
135 136 137 |
# File 'lib/parliament/grom/decorator/person.rb', line 135 def current_party @current_party ||= party_memberships.select(&:current?).select(&:party)&.first&.party end |
#current_party_membership ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
142 143 144 |
# File 'lib/parliament/grom/decorator/person.rb', line 142 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.
271 272 273 |
# File 'lib/parliament/grom/decorator/person.rb', line 271 def display_name respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name end |
#ex_officio? ⇒ Boolean
Check whether member is an ex_officio?.
215 216 217 |
# File 'lib/parliament/grom/decorator/person.rb', line 215 def ex_officio? respond_to?(:memberHasExOfficioMembership) end |
#facebook_weblinks ⇒ Array
Alias personHasFacebookWebLink with fallback.
313 314 315 |
# File 'lib/parliament/grom/decorator/person.rb', line 313 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 personHasFormalBodyMembership with fallback.
285 286 287 |
# File 'lib/parliament/grom/decorator/person.rb', line 285 def formal_body_memberships respond_to?(:personHasFormalBodyMembership) ? personHasFormalBodyMembership : [] end |
#former_lord? ⇒ Boolean
Check whether they are a former member of the House of Lords.
245 246 247 |
# File 'lib/parliament/grom/decorator/person.rb', line 245 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.
201 202 203 |
# File 'lib/parliament/grom/decorator/person.rb', line 201 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.
264 265 266 |
# File 'lib/parliament/grom/decorator/person.rb', line 264 def full_title respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : '' end |
#gender ⇒ Array
Alias genderIdentityHasGender with fallback.
163 164 165 |
# File 'lib/parliament/grom/decorator/person.rb', line 163 def gender gender_identities.empty? ? nil : gender_identities.first.gender end |
#gender_identities ⇒ Array
Alias personHasGenderIdentity with fallback.
156 157 158 |
# File 'lib/parliament/grom/decorator/person.rb', line 156 def gender_identities respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : [] end |
#gender_pronoun ⇒ String
Gets the gender pronoun of the Grom::Node.
170 171 172 173 174 175 176 |
# File 'lib/parliament/grom/decorator/person.rb', line 170 def gender_pronoun if gender return 'She' if gender.name == 'Female' return 'He' if gender.name == 'Male' end 'They' 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.
292 293 294 |
# File 'lib/parliament/grom/decorator/person.rb', line 292 def government_incumbencies respond_to?(:governmentPersonHasGovernmentIncumbency) ? governmentPersonHasGovernmentIncumbency : [] end |
#houses ⇒ Array
Alias houseSeatHasHouse with fallback.
107 108 109 |
# File 'lib/parliament/grom/decorator/person.rb', line 107 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?.
229 230 231 |
# File 'lib/parliament/grom/decorator/person.rb', line 229 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.
128 129 130 |
# File 'lib/parliament/grom/decorator/person.rb', line 128 def parties @parties ||= party_memberships.map(&:party).flatten.uniq.compact end |
#party_memberships ⇒ Array
Alias partyMemberHasPartyMembership with fallback.
121 122 123 |
# File 'lib/parliament/grom/decorator/person.rb', line 121 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
253 254 255 256 257 258 259 |
# File 'lib/parliament/grom/decorator/person.rb', line 253 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.
299 300 301 |
# File 'lib/parliament/grom/decorator/person.rb', line 299 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.include?(Parliament::Utils::Helpers::RequestHelper.namespace_uri_schema_path('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.
278 279 280 |
# File 'lib/parliament/grom/decorator/person.rb', line 278 def sort_name respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : '' end |
#statuses ⇒ Hash
Checks the statuses of the Grom::Node.
181 182 183 184 185 186 187 188 189 |
# File 'lib/parliament/grom/decorator/person.rb', line 181 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.
306 307 308 |
# File 'lib/parliament/grom/decorator/person.rb', line 306 def twitter_weblinks [*get_weblinks_by_predicate(:personHasTwitterWebLink)] end |
#weblinks? ⇒ Boolean
Check whether a person has any weblinks
318 319 320 |
# File 'lib/parliament/grom/decorator/person.rb', line 318 def weblinks? (personal_weblinks + twitter_weblinks + facebook_weblinks).any? end |