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

Since:

  • 0.1.0



212
213
214
# File 'lib/parliament/grom/decorator/person.rb', line 212

def alternate?
  respond_to?(:memberHasAlternateMembership)
end

#constituenciesArray

Alias houseSeatHasConstituencyGroup with fallback.

Since:

  • 0.1.0



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

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

#contact_pointsArray

Alias personHasContactPoint with fallback.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



184
185
186
# File 'lib/parliament/grom/decorator/person.rb', line 184

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

#current_partyGrom::Node

Alias partyMembershipHasParty with fallback.

Since:

  • 0.1.0



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

Alias partyMembershipHasParty with fallback.

Since:

  • 0.1.0



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

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

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.

Since:

  • 0.1.0



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

Since:

  • 0.1.0



205
206
207
# File 'lib/parliament/grom/decorator/person.rb', line 205

def ex_officio?
  respond_to?(:memberHasExOfficioMembership)
end

Alias personHasFacebookWebLink with fallback.

Since:

  • 0.1.0



294
295
296
# File 'lib/parliament/grom/decorator/person.rb', line 294

def facebook_weblinks
  [*get_weblinks_by_predicate(:personHasFacebookWebLink)]
end

#family_nameString

Alias personFamilyName with fallback.

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 memberHasFormalBodyMembership with fallback.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



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.

Since:

  • 0.1.0



191
192
193
# File 'lib/parliament/grom/decorator/person.rb', line 191

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

#full_nameString

Builds a full name using personGivenName and personFamilyName.

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.

Since:

  • 0.1.0



245
246
247
# File 'lib/parliament/grom/decorator/person.rb', line 245

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

#genderArray

Alias genderIdentityHasGender with fallback.

Since:

  • 0.1.0



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

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

#gender_identitiesArray

Alias personHasGenderIdentity with fallback.

Since:

  • 0.1.0



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

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

#given_nameString

Alias personGivenName with fallback.

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.

Since:

  • 0.1.0



273
274
275
# File 'lib/parliament/grom/decorator/person.rb', line 273

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

#housesArray

Alias houseSeatHasHouse with fallback.

Since:

  • 0.1.0



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.

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.

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

Since:

  • 0.1.0



219
220
221
# File 'lib/parliament/grom/decorator/person.rb', line 219

def lay_member?
  respond_to?(:formalBodyLayPersonMnisId)
end

#mnis_idArray

Alias memberMnisId with fallback.

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.

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.

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.

Since:

  • 0.1.0



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

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

#party_membershipsArray

Alias partyMemberHasPartyMembership with fallback.

Since:

  • 0.1.0



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

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

Since:

  • 0.1.0



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

Alias personHasPersonalWebLink with fallback.

Since:

  • 0.1.0



280
281
282
# File 'lib/parliament/grom/decorator/person.rb', line 280

def personal_weblinks
  [*get_weblinks_by_predicate(:personHasPersonalWebLink)]
end

#pims_idArray

Alias personPimsId with fallback.

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.

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 == 'https://id.parliament.uk/schema/SeatIncumbency' }
end

#seatsArray

Alias seatIncumbencyHasHouseSeat with fallback.

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.

Since:

  • 0.1.0



259
260
261
# File 'lib/parliament/grom/decorator/person.rb', line 259

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

#statusesHash

Checks the statuses of the Grom::Node.

Since:

  • 0.1.0



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

Alias personHasTwitterWebLink with fallback.

Since:

  • 0.1.0



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

Since:

  • 0.1.0



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

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