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

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helpers::DateHelper

#date_range

Instance Method Details

#constituenciesArray

Alias houseSeatHasConstituencyGroup with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



99
100
101
# File 'lib/parliament/grom/decorator/person.rb', line 99

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



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

Returns:

  • (Boolean)

    a boolean depending on whether or not the result of #statuses includes ‘Member of the House of Lords’.

Since:

  • 0.1.0



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

Returns:

  • (Boolean)

    a boolean depending on whether or not the result of #statuses includes ‘Current MP’.

Since:

  • 0.1.0



168
169
170
# File 'lib/parliament/grom/decorator/person.rb', line 168

def current_mp?
  statuses[:house_membership_status].include?('Current MP')
end

#current_partyGrom::Node

Alias partyMembershipHasParty with fallback.

Returns:

  • (Grom::Node)

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

Since:

  • 0.1.0



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

Alias partyMembershipHasParty with fallback.

Returns:

  • (Grom::Node)

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

Since:

  • 0.1.0



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

Alias personDateOfBirth with fallback.

Returns:

  • (DateTime, nil)

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

Since:

  • 0.1.0



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_nameString

Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.

Returns:

  • (String, String)

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

Since:

  • 0.1.0



189
190
191
# File 'lib/parliament/grom/decorator/person.rb', line 189

def display_name
  respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name
end

Alias personHasFacebookWebLink with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



231
232
233
# File 'lib/parliament/grom/decorator/person.rb', line 231

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



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

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

#formal_body_membershipsArray

Alias memberHasFormalBodyMembership with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



203
204
205
# File 'lib/parliament/grom/decorator/person.rb', line 203

def formal_body_memberships
  respond_to?(:memberHasFormalBodyMembership) ? memberHasFormalBodyMembership : []
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



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_titleString

Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.

Returns:

  • (String, String)

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

Since:

  • 0.1.0



182
183
184
# File 'lib/parliament/grom/decorator/person.rb', line 182

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



148
149
150
# File 'lib/parliament/grom/decorator/person.rb', line 148

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



141
142
143
# File 'lib/parliament/grom/decorator/person.rb', line 141

def gender_identities
  respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
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



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

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

#government_incumbenciesArray

Alias governmentIncumbency with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



210
211
212
# File 'lib/parliament/grom/decorator/person.rb', line 210

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

#house_incumbenciesArray

Alias memberHasParliamentaryIncumbency with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

#housesArray

Alias houseSeatHasHouse with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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.

Returns:

  • (String, String)

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

Since:

  • 0.1.0



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

#incumbenciesArray

Alias memberHasParliamentaryIncumbency with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

def incumbencies
  respond_to?(:memberHasParliamentaryIncumbency) ? memberHasParliamentaryIncumbency : []
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



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

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



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

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



106
107
108
# File 'lib/parliament/grom/decorator/person.rb', line 106

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

Alias personHasPersonalWebLink with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



217
218
219
# File 'lib/parliament/grom/decorator/person.rb', line 217

def personal_weblinks
  [*get_weblinks_by_predicate(:personHasPersonalWebLink)]
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



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

#seatsArray

Alias seatIncumbencyHasHouseSeat with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



85
86
87
# File 'lib/parliament/grom/decorator/person.rb', line 85

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



196
197
198
# File 'lib/parliament/grom/decorator/person.rb', line 196

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



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

Alias personHasTwitterWebLink with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

Returns:

  • (Boolean)

Since:

  • 0.1.0



236
237
238
# File 'lib/parliament/grom/decorator/person.rb', line 236

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