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.ukpds.org/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.

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.

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

Alias partyMembershipHasParty with fallback.

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.

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.

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.

Since:

  • 0.1.0



175
176
177
# File 'lib/parliament/grom/decorator/person.rb', line 175

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

#family_nameString

Alias personFamilyName with fallback.

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.

Since:

  • 0.1.0



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

def formal_body_memberships
  respond_to?(:memberHasFormalBodyMembership) ? memberHasFormalBodyMembership : []
end

#full_nameString

Builds a full name using personGivenName and personFamilyName.

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.

Since:

  • 0.1.0



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

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

#genderArray

Alias genderIdentityHasGender with fallback.

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.

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.

Since:

  • 0.1.0



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

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

#house_incumbenciesArray

Alias memberHasIncumbency with fallback.

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 == 'http://id.ukpds.org/schema/HouseIncumbency' }
end

#housesArray

Alias houseSeatHasHouse with fallback.

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.

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

Since:

  • 0.1.0



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

def incumbencies
  respond_to?(:memberHasIncumbency) ? memberHasIncumbency : []
end

#other_nameString

Alias personOtherNames with fallback.

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.

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.

Since:

  • 0.1.0



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

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

#seat_incumbenciesArray

Alias memberHasIncumbency with fallback.

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 == 'http://id.ukpds.org/schema/SeatIncumbency' }
end

#seatsArray

Alias seatIncumbencyHasHouseSeat with fallback.

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.

Since:

  • 0.1.0



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

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

#statusesHash

Checks the statuses of the Grom::Node.

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