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.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#area ⇒ Grom::Node?
Alias constituencyGroupHasConstituencyArea with fallback.
-
#contact_points ⇒ Array
Alias parliamentaryIncumbencyHasContactPoint with fallback.
-
#correct? ⇒ Boolean
Checks if Grom::Node is the correct constituency.
-
#current? ⇒ Boolean
Checks if Grom::Node has an end date.
-
#current_member_display_name ⇒ Array
Alias parliamentaryIncumbencyHasMember with fallback.
-
#current_member_party_name ⇒ String
Alias party_name with fallback.
-
#end_date ⇒ DateTime?
Alias constituencyGroupEndDate with fallback.
-
#members ⇒ Array
Alias parliamentaryIncumbencyHasMember with fallback.
-
#name ⇒ String
Alias constituencyGroupName with fallback.
-
#regions ⇒ Array
The regions of the Grom::Node or an empty array.
-
#seat_incumbencies ⇒ Array
Alias houseSeatHasSeatIncumbency with fallback.
-
#seats ⇒ Array
Alias constituencyGroupHasHouseSeat with fallback.
-
#start_date ⇒ DateTime?
Alias constituencyGroupStartDate with fallback.
Methods included from Helpers::DateHelper
Instance Attribute Details
#correct ⇒ Object
10 11 12 |
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 10 def correct @correct end |
Instance Method Details
#area ⇒ Grom::Node?
Alias constituencyGroupHasConstituencyArea with fallback.
70 71 72 |
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 70 def area respond_to?(:constituencyGroupHasConstituencyArea) ? constituencyGroupHasConstituencyArea.first : nil end |
#contact_points ⇒ Array
Alias parliamentaryIncumbencyHasContactPoint with fallback.
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.
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.
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_name ⇒ Array
Alias parliamentaryIncumbencyHasMember with fallback.
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_name ⇒ String
Alias party_name with fallback.
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_date ⇒ DateTime?
Alias constituencyGroupEndDate with fallback.
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 |
#members ⇒ Array
Alias parliamentaryIncumbencyHasMember with fallback.
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 |
#name ⇒ String
Alias constituencyGroupName with fallback.
14 15 16 |
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 14 def name respond_to?(:constituencyGroupName) ? constituencyGroupName : '' end |
#regions ⇒ Array
Returns the regions of the Grom::Node or an empty array.
127 128 129 |
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 127 def regions respond_to?(:inEuropeanRegion) ? inEuropeanRegion : [] end |
#seat_incumbencies ⇒ Array
Alias houseSeatHasSeatIncumbency with fallback.
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 |
#seats ⇒ Array
Alias constituencyGroupHasHouseSeat with fallback.
35 36 37 |
# File 'lib/parliament/grom/decorator/constituency_group.rb', line 35 def seats respond_to?(:constituencyGroupHasHouseSeat) ? constituencyGroupHasHouseSeat : [] end |
#start_date ⇒ DateTime?
Alias constituencyGroupStartDate with fallback.
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 |