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

Includes:
Helpers::DateHelper
Defined in:
lib/parliament/grom/decorator/constituency_group.rb

Overview

Decorator namespace for Grom::Node instances with type: id.parliament.uk/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

Methods included from Helpers::DateHelper

#date_range

Instance Attribute Details

#correctObject

Since:

  • 0.1.0



10
11
12
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 10

def correct
  @correct
end

Instance Method Details

#areaGrom::Node?

Alias constituencyGroupHasConstituencyArea with fallback.

Returns:

Since:

  • 0.1.0



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

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

#contact_pointsArray

Alias parliamentaryIncumbencyHasContactPoint with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

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



100
101
102
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 100

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



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

def current?
  has_end_date = respond_to?(:constituencyGroupEndDate)

  !has_end_date
end

#current_member_display_nameArray

Alias parliamentaryIncumbencyHasMember with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

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
# 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

  return @party_name = nil unless current_incumbency

  current_membership = current_incumbency.member.party_memberships.select(&:current?).first
  @party_name = current_membership.nil? ? nil : current_membership.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



28
29
30
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 28

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

#membersArray

Alias parliamentaryIncumbencyHasMember with fallback.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



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

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



14
15
16
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 14

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

#regionsArray

Returns the regions of the Grom::Node or an empty array.

Returns:

  • (Array, Array)

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

Since:

  • 0.1.0



127
128
129
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 127

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



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

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



35
36
37
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 35

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



21
22
23
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 21

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