Module: Parliament::Grom::Decorator::ConstituencyGroup

Defined in:
lib/parliament/grom/decorator/constituency_group.rb

Overview

Decorator namespace for Grom::Node instances with type: id.ukpds.org/schema/ConstituencyGroup

attr [Boolean] correct verifies that the Grom::Node is the expected constituency. This is used in conjunction with postcode lookup to verify if the Grom::Node is the expected constituency.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#correctObject

Since:

  • 0.1.0



8
9
10
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 8

def correct
  @correct
end

Instance Method Details

#areaGrom::Node?

Alias constituencyGroupHasConstituencyArea with fallback.

Returns:

Since:

  • 0.1.0



68
69
70
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 68

def area
  respond_to?(:constituencyGroupHasConstituencyArea) ? constituencyGroupHasConstituencyArea.first : nil
end

#contact_pointsArray

Alias incumbencyHasContactPoint with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



75
76
77
78
79
80
81
82
83
84
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 75

def contact_points
  return @contact_points unless @contact_points.nil?

  contact_points = []
  seat_incumbencies.each do |seat_incumbency|
    contact_points << seat_incumbency.contact_points
  end

  @contact_points = contact_points.flatten.uniq
end

#correct?Boolean

Checks if Grom::Node is the correct constituency.

Returns:

  • (Boolean)

    a boolean depending on whether or not the Grom::Node is the expected constituency.

Since:

  • 0.1.0



98
99
100
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 98

def correct?
  @correct || false
end

#current?Boolean

Checks if Grom::Node has an end date.

Returns:

  • (Boolean)

    a boolean depending on whether or not the Grom::Node has an end date.

Since:

  • 0.1.0



89
90
91
92
93
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 89

def current?
  has_end_date = respond_to?(:constituencyGroupEndDate)

  !has_end_date
end

#current_member_display_nameArray

Alias incumbencyHasMember with fallback.

Returns:

  • (Array, Array)

    the current member of the Grom::Node has a display name.

Since:

  • 0.1.0



106
107
108
109
110
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 106

def current_member_display_name
  return @current_member_display_name unless @current_member_display_name.nil?
  current_incumbency = seat_incumbencies.select(&:current?).first
  @current_member_display_name = current_incumbency.nil? ? nil : current_incumbency.member.display_name
end

#current_member_party_nameString

Alias party_name with fallback.

Returns:

  • (String, String)

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

Since:

  • 0.1.0



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 116

def current_member_party_name
  return @party_name unless @party_name.nil?
  current_incumbency = seat_incumbencies.select(&:current?).first

  if current_incumbency
    current_membership = current_incumbency.member.party_memberships.select(&:current?).first
    @party_name = current_membership.nil? ? nil : current_membership.party.name
  else
    @party_name = nil
  end
    @party_name
end

#end_dateDateTime?

Alias constituencyGroupEndDate with fallback.

Returns:

  • (DateTime, nil)

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

Since:

  • 0.1.0



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

def end_date
  @end_date ||= respond_to?(:constituencyGroupEndDate) ? DateTime.parse(constituencyGroupEndDate) : nil
end

#membersArray

Alias incumbencyHasMember with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



54
55
56
57
58
59
60
61
62
63
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 54

def members
  return @members unless @members.nil?

  members = []
  seat_incumbencies.each do |seat_incumbency|
    members << seat_incumbency.member
  end

  @members = members.flatten.uniq
end

#nameString

Alias constituencyGroupName with fallback.

Returns:

  • (String, String)

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

Since:

  • 0.1.0



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

def name
  respond_to?(:constituencyGroupName) ? constituencyGroupName : ''
end

#seat_incumbenciesArray

Alias houseSeatHasSeatIncumbency with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



40
41
42
43
44
45
46
47
48
49
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 40

def seat_incumbencies
  return @seat_incumbencies unless @seat_incumbencies.nil?

  seat_incumbencies = []
  seats.each do |seat|
    seat_incumbencies << seat.seat_incumbencies
  end

  @seat_incumbencies = seat_incumbencies.flatten.uniq
end

#seatsArray

Alias constituencyGroupHasHouseSeat with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



33
34
35
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 33

def seats
  respond_to?(:constituencyGroupHasHouseSeat) ? constituencyGroupHasHouseSeat : []
end

#start_dateDateTime?

Alias constituencyGroupStartDate with fallback.

Returns:

  • (DateTime, nil)

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

Since:

  • 0.1.0



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

def start_date
  @start_date ||= respond_to?(:constituencyGroupStartDate) ? DateTime.parse(constituencyGroupStartDate) : nil
end