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.

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helpers::DateHelper

#date_range

Instance Method Details

#alternate?Boolean

Check whether member is an alternate?.

Returns:

  • (Boolean)

    a boolean depending on whether or not member is an alternate?

Since:

  • 0.1.0



222
223
224
# File 'lib/parliament/grom/decorator/person.rb', line 222

def alternate?
  respond_to?(:memberHasAlternateMembership)
end

#committee_membership_typeObject

Since:

  • 0.1.0



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

#constituenciesArray

Alias houseSeatHasConstituencyGroup with fallback.

Returns:

  • (Array, Array)

    the constituencies of the Grom::Node or an empty array.

Since:

  • 0.1.0



114
115
116
# File 'lib/parliament/grom/decorator/person.rb', line 114

def constituencies
  @constituencies ||= seats.map(&:constituency).flatten.uniq.compact
end

#contact_pointsArray

Alias personHasContactPoint with fallback.

Returns:

  • (Array, Array)

    the contact points of the Grom::Node or an empty array.

Since:

  • 0.1.0



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.

Returns:

  • (Boolean)

    a boolean depending on whether or not they have a current seat incumbency in the House of Lords.

Since:

  • 0.1.0



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.

Returns:

  • (Boolean)

    a boolean depending on whether or not they have a current seat incumbency in the House of Commons.

Since:

  • 0.1.0



194
195
196
# File 'lib/parliament/grom/decorator/person.rb', line 194

def current_mp?
  current_member_by_house?('House of Commons')
end

#current_partyGrom::Node

Alias partyMembershipHasParty with fallback.

Returns:

  • (Grom::Node)

    the current party of the Grom::Node or nil.

Since:

  • 0.1.0



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_membershipGrom::Node

Alias partyMembershipHasParty with fallback.

Returns:

  • (Grom::Node)

    the current party membership of the Grom::Node or nil.

Since:

  • 0.1.0



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_incumbencyGrom::Node

Returns the seat incumbency as a Grom::Node or nil.

Returns:

  • (Grom::Node)

    the seat incumbency as a Grom::Node or nil

Since:

  • 0.1.0



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_birthDateTime?

Alias personDateOfBirth with fallback.

Returns:

  • (DateTime, nil)

    the date of birth of the Grom::Node or nil.

Since:

  • 0.1.0



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_nameString

Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.

Returns:

  • (String, String)

    the display name of the Grom::Node or the full name.

Since:

  • 0.1.0



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?.

Returns:

  • (Boolean)

    a boolean depending on whether or not member is an ex_officio?

Since:

  • 0.1.0



215
216
217
# File 'lib/parliament/grom/decorator/person.rb', line 215

def ex_officio?
  respond_to?(:memberHasExOfficioMembership)
end

Alias personHasFacebookWebLink with fallback.

Returns:

  • (Array, Array)

    all the Facebook weblinks of the Grom::Node or an empty array.

Since:

  • 0.1.0



313
314
315
# File 'lib/parliament/grom/decorator/person.rb', line 313

def facebook_weblinks
  [*get_weblinks_by_predicate(:personHasFacebookWebLink)]
end

#family_nameString

Alias personFamilyName with fallback.

Returns:

  • (String, String)

    the family name of the Grom::Node or an empty string.

Since:

  • 0.1.0



18
19
20
# File 'lib/parliament/grom/decorator/person.rb', line 18

def family_name
  respond_to?(:personFamilyName) ? personFamilyName : ''
end

#formal_body_membershipsArray

Alias personHasFormalBodyMembership with fallback.

Returns:

  • (Array, Array)

    all the formal body memberships of the Grom::Node or an empty array.

Since:

  • 0.1.0



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.

Returns:

  • (Boolean)

    a boolean depending on whether or not they have a current seat incumbency in the House of Lords.

Since:

  • 0.1.0



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.

Returns:

  • (Boolean)

    a boolean depending on whether or not they have a current seat incumbency in the House of Commons.

Since:

  • 0.1.0



201
202
203
# File 'lib/parliament/grom/decorator/person.rb', line 201

def former_mp?
  former_member_by_house?('House of Commons')
end

#full_nameString

Builds a full name using personGivenName and personFamilyName.

Returns:

  • (String, String)

    the full name of the Grom::Node or an empty string.

Since:

  • 0.1.0



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_titleString

Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.

Returns:

  • (String, String)

    the full title of the Grom::Node or an empty string.

Since:

  • 0.1.0



264
265
266
# File 'lib/parliament/grom/decorator/person.rb', line 264

def full_title
  respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : ''
end

#genderArray

Alias genderIdentityHasGender with fallback.

Returns:

  • (Array, Array)

    the gender of the Grom::Node or nil.

Since:

  • 0.1.0



163
164
165
# File 'lib/parliament/grom/decorator/person.rb', line 163

def gender
  gender_identities.empty? ? nil : gender_identities.first.gender
end

#gender_identitiesArray

Alias personHasGenderIdentity with fallback.

Returns:

  • (Array, Array)

    the gender identities of the Grom::Node or an empty array.

Since:

  • 0.1.0



156
157
158
# File 'lib/parliament/grom/decorator/person.rb', line 156

def gender_identities
  respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
end

#gender_pronounString

Gets the gender pronoun of the Grom::Node.

Returns:

  • (String, String)

    the gender pronoun of the Grom::Node.

Since:

  • 0.1.0



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_nameString

Alias personGivenName with fallback.

Returns:

  • (String, String)

    the given name of the Grom::Node or an empty string.

Since:

  • 0.1.0



11
12
13
# File 'lib/parliament/grom/decorator/person.rb', line 11

def given_name
  respond_to?(:personGivenName) ? personGivenName : ''
end

#government_incumbenciesArray

Alias governmentIncumbency with fallback.

Returns:

  • (Array, Array)

    all the government incumbencies of the Grom::Node or an empty array.

Since:

  • 0.1.0



292
293
294
# File 'lib/parliament/grom/decorator/person.rb', line 292

def government_incumbencies
  respond_to?(:governmentPersonHasGovernmentIncumbency) ? governmentPersonHasGovernmentIncumbency : []
end

#housesArray

Alias houseSeatHasHouse with fallback.

Returns:

  • (Array, Array)

    the houses of the Grom::Node or an empty array.

Since:

  • 0.1.0



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.

Returns:

  • (String, String)

    the image location of the Grom::Node or a placeholder string.

Since:

  • 0.1.0



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

#incumbenciesArray

Alias memberHasParliamentaryIncumbency with fallback.

Returns:

  • (Array, Array)

    all the incumbencies of the Grom::Node or an empty array.

Since:

  • 0.1.0



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?.

Returns:

  • (Boolean)

    a boolean depending on whether or person is a lay member or not

Since:

  • 0.1.0



229
230
231
# File 'lib/parliament/grom/decorator/person.rb', line 229

def lay_member?
  respond_to?(:formalBodyLayPersonMnisId)
end

#mnis_idArray

Alias memberMnisId with fallback.

Returns:

  • (Array, Array)

    the mnis_id of the Grom::Node or nil.

Since:

  • 0.1.0



70
71
72
# File 'lib/parliament/grom/decorator/person.rb', line 70

def mnis_id
  respond_to?(:memberMnisId) ? memberMnisId : nil
end

#most_recent_seat_incumbencyGrom::Node

Returns the most recent seat incumbency as a Grom::Node or nil.

Returns:

  • (Grom::Node)

    the most recent seat incumbency as a Grom::Node or nil

Since:

  • 0.1.0



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_nameString

Alias personOtherNames with fallback.

Returns:

  • (String, String)

    the other names of the Grom::Node or an empty string.

Since:

  • 0.1.0



25
26
27
# File 'lib/parliament/grom/decorator/person.rb', line 25

def other_name
  respond_to?(:personOtherNames) ? personOtherNames : ''
end

#partiesArray

Alias partyMembershipHasParty with fallback.

Returns:

  • (Array, Array)

    the parties of the Grom::Node or an empty array.

Since:

  • 0.1.0



128
129
130
# File 'lib/parliament/grom/decorator/person.rb', line 128

def parties
  @parties ||= party_memberships.map(&:party).flatten.uniq.compact
end

#party_membershipsArray

Alias partyMemberHasPartyMembership with fallback.

Returns:

  • (Array, Array)

    the party memberships of the Grom::Node or an empty array.

Since:

  • 0.1.0



121
122
123
# File 'lib/parliament/grom/decorator/person.rb', line 121

def party_memberships
  respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
end

#person_typeString

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

Returns:

  • (String)

    ‘member’ if they are a member, ‘lord’ if they are a lord.

Since:

  • 0.1.0



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

Alias personHasPersonalWebLink with fallback.

Returns:

  • (Array, Array)

    all the personal weblinks of the Grom::Node or an empty Array.

Since:

  • 0.1.0



299
300
301
# File 'lib/parliament/grom/decorator/person.rb', line 299

def personal_weblinks
  [*get_weblinks_by_predicate(:personHasPersonalWebLink)]
end

#pims_idArray

Alias personPimsId with fallback.

Returns:

  • (Array, Array)

    the pims_id of the Grom::Node or nil.

Since:

  • 0.1.0



63
64
65
# File 'lib/parliament/grom/decorator/person.rb', line 63

def pims_id
  respond_to?(:personPimsId) ? personPimsId : nil
end

#seat_incumbenciesArray

Alias memberHasParliamentaryIncumbency with fallback.

Returns:

  • (Array, Array)

    the seat incumbencies of the Grom::Node or an empty array.

Since:

  • 0.1.0



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

#seatsArray

Alias seatIncumbencyHasHouseSeat with fallback.

Returns:

  • (Array, Array)

    the seats of the Grom::Node or an empty array.

Since:

  • 0.1.0



101
102
103
# File 'lib/parliament/grom/decorator/person.rb', line 101

def seats
  @seats ||= seat_incumbencies.map(&:seat).flatten.uniq.compact
end

#sort_nameString

Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.

Returns:

  • (String, String)

    the sort name of the Grom::Node or an empty string.

Since:

  • 0.1.0



278
279
280
# File 'lib/parliament/grom/decorator/person.rb', line 278

def sort_name
  respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : ''
end

#statusesHash

Checks the statuses of the Grom::Node.

Returns:

  • (Hash, Hash)

    the statuses of the Grom::Node or an empty hash.

Since:

  • 0.1.0



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

Alias personHasTwitterWebLink with fallback.

Returns:

  • (Array, Array)

    all the Twitter weblinks of the Grom::Node or an empty array.

Since:

  • 0.1.0



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

Returns:

  • (Boolean)

Since:

  • 0.1.0



318
319
320
# File 'lib/parliament/grom/decorator/person.rb', line 318

def weblinks?
  (personal_weblinks + twitter_weblinks + facebook_weblinks).any?
end