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. rubocop:disable ModuleLength
Instance Method Summary collapse
-
#constituencies ⇒ Array
Alias houseSeatHasConstituencyGroup with fallback.
-
#contact_points ⇒ Array
Alias personHasContactPoint with fallback.
-
#current_lord? ⇒ Boolean
Check whether #statuses includes ‘Member of the House of Lords’.
-
#current_mp? ⇒ Boolean
Check whether #statuses includes ‘Current MP’.
-
#current_party ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
-
#current_party_membership ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
-
#date_of_birth ⇒ DateTime?
Alias personDateOfBirth with fallback.
-
#display_name ⇒ String
Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
-
#facebook_weblinks ⇒ Array
Alias personHasFacebookWebLink with fallback.
-
#family_name ⇒ String
Alias personFamilyName with fallback.
-
#formal_body_memberships ⇒ Array
Alias memberHasFormalBodyMembership with fallback.
-
#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.
-
#house_incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
-
#houses ⇒ Array
Alias houseSeatHasHouse with fallback.
-
#image_id(show_placeholder: true) ⇒ String
Alias personHasPersonImage with fallback.
-
#incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
-
#other_name ⇒ String
Alias personOtherNames with fallback.
-
#parties ⇒ Array
Alias partyMembershipHasParty with fallback.
-
#party_memberships ⇒ Array
Alias partyMemberHasPartyMembership with fallback.
-
#personal_weblinks ⇒ Array
Alias personHasPersonalWebLink 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
#constituencies ⇒ Array
Alias houseSeatHasConstituencyGroup with fallback.
99 100 101 |
# File 'lib/parliament/grom/decorator/person.rb', line 99 def constituencies @constituencies ||= seats.map(&:constituency).flatten.uniq.compact end |
#contact_points ⇒ Array
Alias personHasContactPoint with fallback.
134 135 136 |
# File 'lib/parliament/grom/decorator/person.rb', line 134 def contact_points respond_to?(:personHasContactPoint) ? personHasContactPoint : [] end |
#current_lord? ⇒ Boolean
Check whether #statuses includes ‘Member of the House of Lords’.
175 176 177 |
# File 'lib/parliament/grom/decorator/person.rb', line 175 def current_lord? statuses[:house_membership_status].include?('Member of the House of Lords') end |
#current_mp? ⇒ Boolean
Check whether #statuses includes ‘Current MP’.
168 169 170 |
# File 'lib/parliament/grom/decorator/person.rb', line 168 def current_mp? statuses[:house_membership_status].include?('Current MP') end |
#current_party ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
120 121 122 |
# File 'lib/parliament/grom/decorator/person.rb', line 120 def current_party @current_party ||= party_memberships.select(&:current?).select(&:party)&.first&.party end |
#current_party_membership ⇒ Grom::Node
Alias partyMembershipHasParty with fallback.
127 128 129 |
# File 'lib/parliament/grom/decorator/person.rb', line 127 def current_party_membership @current_party_membership ||= party_memberships.select(&:current?).select(&:party)&.first end |
#date_of_birth ⇒ DateTime?
Alias personDateOfBirth with fallback.
33 34 35 |
# File 'lib/parliament/grom/decorator/person.rb', line 33 def date_of_birth @date_of_birth ||= respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil end |
#display_name ⇒ String
Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
189 190 191 |
# File 'lib/parliament/grom/decorator/person.rb', line 189 def display_name respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name end |
#facebook_weblinks ⇒ Array
Alias personHasFacebookWebLink with fallback.
231 232 233 |
# File 'lib/parliament/grom/decorator/person.rb', line 231 def facebook_weblinks [*get_weblinks_by_predicate(:personHasFacebookWebLink)] end |
#family_name ⇒ String
Alias personFamilyName with fallback.
19 20 21 |
# File 'lib/parliament/grom/decorator/person.rb', line 19 def family_name respond_to?(:personFamilyName) ? personFamilyName : '' end |
#formal_body_memberships ⇒ Array
Alias memberHasFormalBodyMembership with fallback.
203 204 205 |
# File 'lib/parliament/grom/decorator/person.rb', line 203 def formal_body_memberships respond_to?(:memberHasFormalBodyMembership) ? memberHasFormalBodyMembership : [] end |
#full_name ⇒ String
Builds a full name using personGivenName and personFamilyName.
40 41 42 43 44 45 46 47 48 |
# File 'lib/parliament/grom/decorator/person.rb', line 40 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.
182 183 184 |
# File 'lib/parliament/grom/decorator/person.rb', line 182 def full_title respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : '' end |
#gender ⇒ Array
Alias genderIdentityHasGender with fallback.
148 149 150 |
# File 'lib/parliament/grom/decorator/person.rb', line 148 def gender gender_identities.empty? ? nil : gender_identities.first.gender end |
#gender_identities ⇒ Array
Alias personHasGenderIdentity with fallback.
141 142 143 |
# File 'lib/parliament/grom/decorator/person.rb', line 141 def gender_identities respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : [] end |
#given_name ⇒ String
Alias personGivenName with fallback.
12 13 14 |
# File 'lib/parliament/grom/decorator/person.rb', line 12 def given_name respond_to?(:personGivenName) ? personGivenName : '' end |
#government_incumbencies ⇒ Array
Alias governmentIncumbency with fallback.
210 211 212 |
# File 'lib/parliament/grom/decorator/person.rb', line 210 def government_incumbencies respond_to?(:governmentIncumbency) ? governmentIncumbency : [] end |
#house_incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
78 79 80 |
# File 'lib/parliament/grom/decorator/person.rb', line 78 def house_incumbencies @house_incumbencies ||= incumbencies.select { |inc| inc.type == 'https://id.parliament.uk/schema/HouseIncumbency' } end |
#houses ⇒ Array
Alias houseSeatHasHouse with fallback.
92 93 94 |
# File 'lib/parliament/grom/decorator/person.rb', line 92 def houses @houses ||= [seats.map(&:house), house_incumbencies.map(&:house)].flatten.uniq.compact end |
#image_id(show_placeholder: true) ⇒ String
Alias personHasPersonImage with fallback.
53 54 55 56 57 58 59 |
# File 'lib/parliament/grom/decorator/person.rb', line 53 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.
64 65 66 |
# File 'lib/parliament/grom/decorator/person.rb', line 64 def incumbencies respond_to?(:memberHasParliamentaryIncumbency) ? memberHasParliamentaryIncumbency : [] end |
#other_name ⇒ String
Alias personOtherNames with fallback.
26 27 28 |
# File 'lib/parliament/grom/decorator/person.rb', line 26 def other_name respond_to?(:personOtherNames) ? personOtherNames : '' end |
#parties ⇒ Array
Alias partyMembershipHasParty with fallback.
113 114 115 |
# File 'lib/parliament/grom/decorator/person.rb', line 113 def parties @parties ||= party_memberships.map(&:party).flatten.uniq.compact end |
#party_memberships ⇒ Array
Alias partyMemberHasPartyMembership with fallback.
106 107 108 |
# File 'lib/parliament/grom/decorator/person.rb', line 106 def party_memberships respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : [] end |
#personal_weblinks ⇒ Array
Alias personHasPersonalWebLink with fallback.
217 218 219 |
# File 'lib/parliament/grom/decorator/person.rb', line 217 def personal_weblinks [*get_weblinks_by_predicate(:personHasPersonalWebLink)] end |
#seat_incumbencies ⇒ Array
Alias memberHasParliamentaryIncumbency with fallback.
71 72 73 |
# File 'lib/parliament/grom/decorator/person.rb', line 71 def seat_incumbencies @seat_incumbencies ||= incumbencies.select { |inc| inc.type == 'https://id.parliament.uk/schema/SeatIncumbency' } end |
#seats ⇒ Array
Alias seatIncumbencyHasHouseSeat with fallback.
85 86 87 |
# File 'lib/parliament/grom/decorator/person.rb', line 85 def seats @seats ||= seat_incumbencies.map(&:seat).flatten.uniq.compact end |
#sort_name ⇒ String
Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.
196 197 198 |
# File 'lib/parliament/grom/decorator/person.rb', line 196 def sort_name respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : '' end |
#statuses ⇒ Hash
Checks the statuses of the Grom::Node.
155 156 157 158 159 160 161 162 163 |
# File 'lib/parliament/grom/decorator/person.rb', line 155 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.
224 225 226 |
# File 'lib/parliament/grom/decorator/person.rb', line 224 def twitter_weblinks [*get_weblinks_by_predicate(:personHasTwitterWebLink)] end |
#weblinks? ⇒ Boolean
Check whether a person has any weblinks
236 237 238 |
# File 'lib/parliament/grom/decorator/person.rb', line 236 def weblinks? (personal_weblinks + twitter_weblinks + facebook_weblinks).any? end |