parliament-ruby 0.5.19 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -3
  3. data/.travis.yml +0 -1
  4. data/Gemfile +2 -0
  5. data/Makefile +9 -4
  6. data/README.md +185 -11
  7. data/Rakefile +1 -1
  8. data/lib/parliament/client_error.rb +21 -0
  9. data/lib/parliament/decorator/constituency_area.rb +27 -0
  10. data/lib/parliament/{decorators → decorator}/constituency_group.rb +29 -1
  11. data/lib/parliament/decorator/contact_point.rb +48 -0
  12. data/lib/parliament/decorator/gender.rb +13 -0
  13. data/lib/parliament/decorator/gender_identity.rb +13 -0
  14. data/lib/parliament/decorator/house.rb +41 -0
  15. data/lib/parliament/decorator/house_incumbency.rb +50 -0
  16. data/lib/parliament/decorator/house_seat.rb +27 -0
  17. data/lib/parliament/decorator/incumbency.rb +57 -0
  18. data/lib/parliament/decorator/party.rb +27 -0
  19. data/lib/parliament/decorator/party_membership.rb +36 -0
  20. data/lib/parliament/decorator/person.rb +224 -0
  21. data/lib/parliament/{decorators → decorator}/postal_address.rb +5 -1
  22. data/lib/parliament/decorator/seat_incumbency.rb +64 -0
  23. data/lib/parliament/decorator.rb +7 -0
  24. data/lib/parliament/network_error.rb +13 -0
  25. data/lib/parliament/no_content_response_error.rb +19 -0
  26. data/lib/parliament/request.rb +112 -33
  27. data/lib/parliament/response.rb +76 -9
  28. data/lib/parliament/server_error.rb +21 -0
  29. data/lib/parliament/utils.rb +113 -13
  30. data/lib/parliament/version.rb +1 -1
  31. data/lib/parliament.rb +8 -4
  32. data/parliament-ruby.gemspec +6 -6
  33. metadata +32 -28
  34. data/lib/parliament/decorators/constituency_area.rb +0 -17
  35. data/lib/parliament/decorators/contact_point.rb +0 -29
  36. data/lib/parliament/decorators/gender.rb +0 -9
  37. data/lib/parliament/decorators/gender_identity.rb +0 -9
  38. data/lib/parliament/decorators/house.rb +0 -28
  39. data/lib/parliament/decorators/house_incumbency.rb +0 -31
  40. data/lib/parliament/decorators/house_seat.rb +0 -17
  41. data/lib/parliament/decorators/incumbency.rb +0 -35
  42. data/lib/parliament/decorators/party.rb +0 -17
  43. data/lib/parliament/decorators/party_membership.rb +0 -23
  44. data/lib/parliament/decorators/person.rb +0 -152
  45. data/lib/parliament/decorators/seat_incumbency.rb +0 -39
  46. data/lib/parliament/no_content_error.rb +0 -9
@@ -0,0 +1,13 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Gender
4
+ module Gender
5
+ # Alias genderName with fallback.
6
+ #
7
+ # @return [String, String] the gender name of the Grom::Node or an empty string.
8
+ def name
9
+ respond_to?(:genderName) ? genderName : ''
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/GenderIdentity
4
+ module GenderIdentity
5
+ # Alias genderIdentityHasGender with fallback.
6
+ #
7
+ # @return [Grom::Node, nil] a Grom::Node with type http://id.ukpds.org/schema/Gender or nil.
8
+ def gender
9
+ respond_to?(:genderIdentityHasGender) ? genderIdentityHasGender.first : nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/House
4
+ module House
5
+ # Alias houseName with fallback.
6
+ #
7
+ # @return [String, String] the name of the Grom::Node or an empty string.
8
+ def name
9
+ respond_to?(:houseName) ? houseName : ''
10
+ end
11
+
12
+ # Alias houseSeatHasSeatIncumbency with fallback.
13
+ #
14
+ # @return [Array, Array] the seat incumbencies of the Grom::Node or an empty array.
15
+ def seat_incumbencies
16
+ return @seat_incumbencies unless @seat_incumbencies.nil?
17
+
18
+ seat_incumbencies = []
19
+ seats.each do |seat|
20
+ seat_incumbencies << seat.seat_incumbencies
21
+ end
22
+
23
+ @seat_incumbencies = seat_incumbencies.flatten.uniq
24
+ end
25
+
26
+ # Alias houseHasHouseSeat with fallback.
27
+ #
28
+ # @return [Array, Array] the house seats of the Grom::Node or an empty array.
29
+ def seats
30
+ respond_to?(:houseHasHouseSeat) ? houseHasHouseSeat : []
31
+ end
32
+
33
+ # Alias houseHasHouseIncumbency with fallback.
34
+ #
35
+ # @return [Array, Array] the house incumbencies of the Grom::Node or an empty array.
36
+ def house_incumbencies
37
+ respond_to?(:houseHasHouseIncumbency) ? houseHasHouseIncumbency : []
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/HouseIncumbency
4
+ module HouseIncumbency
5
+ # Alias incumbencyStartDate with fallback.
6
+ #
7
+ # @return [DateTime, nil] the start date of the Grom::Node or nil.
8
+ def start_date
9
+ respond_to?(:incumbencyStartDate) ? DateTime.parse(incumbencyStartDate) : nil
10
+ end
11
+
12
+ # Alias incumbencyEndDate with fallback.
13
+ #
14
+ # @return [DateTime, nil] the end date of the Grom::Node or nil.
15
+ def end_date
16
+ respond_to?(:incumbencyEndDate) ? DateTime.parse(incumbencyEndDate) : nil
17
+ end
18
+
19
+ # Checks if Grom::Node has an end date.
20
+ #
21
+ # @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
22
+ def current?
23
+ has_end_date = respond_to?(:incumbencyEndDate)
24
+
25
+ !has_end_date
26
+ end
27
+
28
+ # Alias houseIncumbencyHasHouse with fallback.
29
+ #
30
+ # @return [Grom::Node, nil] the house of the Grom::Node or nil.
31
+ def house
32
+ respond_to?(:houseIncumbencyHasHouse) ? houseIncumbencyHasHouse.first : nil
33
+ end
34
+
35
+ # Alias incumbencyHasMember with fallback.
36
+ #
37
+ # @return [Grom::Node, nil] the member connected to the Grom::Node or nil.
38
+ def member
39
+ respond_to?(:incumbencyHasMember) ? incumbencyHasMember.first : nil
40
+ end
41
+
42
+ # Alias incumbencyHasContactPoint with fallback.
43
+ #
44
+ # @return [Array, Array] the contact points of the Grom::Node or an empty array.
45
+ def contact_points
46
+ respond_to?(:incumbencyHasContactPoint) ? incumbencyHasContactPoint : []
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/HouseSeat
4
+ module HouseSeat
5
+ # Alias houseSeatHasHouse with fallback.
6
+ #
7
+ # @return [Grom::Node, nil] the house of the Grom::Node or nil.
8
+ def house
9
+ respond_to?(:houseSeatHasHouse) ? houseSeatHasHouse.first : nil
10
+ end
11
+
12
+ # Alias houseSeatHasConstituencyGroup with fallback.
13
+ #
14
+ # @return [Grom::Node, nil] the constituency group of the Grom::Node or nil.
15
+ def constituency
16
+ respond_to?(:houseSeatHasConstituencyGroup) ? houseSeatHasConstituencyGroup.first : nil
17
+ end
18
+
19
+ # Alias houseSeatHasSeatIncumbency with fallback.
20
+ #
21
+ # @return [Array, Array] the seat incumbencies of the Grom::Node or an empty.
22
+ def seat_incumbencies
23
+ respond_to?(:houseSeatHasSeatIncumbency) ? houseSeatHasSeatIncumbency : []
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Incumbency
4
+ module Incumbency
5
+ # Alias incumbencyStartDate with fallback.
6
+ #
7
+ # @return [DateTime, nil] the start date of the Grom::Node or nil.
8
+ def start_date
9
+ respond_to?(:incumbencyStartDate) ? DateTime.parse(incumbencyStartDate) : nil
10
+ end
11
+
12
+ # Alias incumbencyEndDate with fallback.
13
+ #
14
+ # @return [DateTime, nil] the end date of the Grom::Node or nil.
15
+ def end_date
16
+ respond_to?(:incumbencyEndDate) ? DateTime.parse(incumbencyEndDate) : nil
17
+ end
18
+
19
+ # Checks if Grom::Node has an end date.
20
+ #
21
+ # @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
22
+ def current?
23
+ has_end_date = respond_to?(:incumbencyEndDate)
24
+
25
+ !has_end_date
26
+ end
27
+
28
+ # Alias incumbencyHasMember with fallback.
29
+ #
30
+ # @return [Grom::Node, nil] the member connected to the Grom::Node or nil.
31
+ def member
32
+ respond_to?(:incumbencyHasMember) ? incumbencyHasMember.first : nil
33
+ end
34
+
35
+ # Alias incumbencyHasContactPoint with fallback.
36
+ #
37
+ # @return [Array, Array] the contact points of the Grom::Node or an empty array.
38
+ def contact_points
39
+ respond_to?(:incumbencyHasContactPoint) ? incumbencyHasContactPoint : []
40
+ end
41
+
42
+ # Alias seatIncumbencyHasHouseSeat with fallback.
43
+ #
44
+ # @return [Grom::Node, nil] the seat of the Grom::Node or nil.
45
+ def seat
46
+ respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
47
+ end
48
+
49
+ # Alias houseIncumbencyHasHouse with fallback.
50
+ #
51
+ # @return [Grom::Node, nil] the house of the Grom::Node or nil.
52
+ def house
53
+ respond_to?(:houseIncumbencyHasHouse) ? houseIncumbencyHasHouse.first : nil
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Party
4
+ module Party
5
+ # Alias partyName with fallback.
6
+ #
7
+ # @return [String, String] the party name of the Grom::Node or an empty string.
8
+ def name
9
+ respond_to?(:partyName) ? partyName : ''
10
+ end
11
+
12
+ # Alias partyHasPartyMembership with fallback.
13
+ #
14
+ # @return [Array, Array] the party memberships of the Grom::Node or an empty array.
15
+ def party_memberships
16
+ respond_to?(:partyHasPartyMembership) ? partyHasPartyMembership : []
17
+ end
18
+
19
+ # Alias count with fallback.
20
+ #
21
+ # @return [Integer, nil] the count of members of the Grom::Node or nil.
22
+ def member_count
23
+ respond_to?(:count) ? count.to_i : nil
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/PartyMembership
4
+ module PartyMembership
5
+ # Alias partyMembershipHasParty with fallback.
6
+ #
7
+ # @return [Grom::Node, nil] the party of the Grom::Node or nil.
8
+ def party
9
+ respond_to?(:partyMembershipHasParty) ? partyMembershipHasParty.first : nil
10
+ end
11
+
12
+ # Alias partyMembershipStartDate with fallback.
13
+ #
14
+ # @return [DateTime, nil] the start date of the Grom::Node or nil.
15
+ def start_date
16
+ respond_to?(:partyMembershipStartDate) ? DateTime.parse(partyMembershipStartDate) : nil
17
+ end
18
+
19
+ # Alias partyMembershipEndDate with fallback.
20
+ #
21
+ # @return [DateTime, nil] the end date of the Grom::Node or nil.
22
+ def end_date
23
+ respond_to?(:partyMembershipEndDate) ? DateTime.parse(partyMembershipEndDate) : nil
24
+ end
25
+
26
+ # Checks if Grom::Node has an end date.
27
+ #
28
+ # @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
29
+ def current?
30
+ has_end_date = respond_to?(:partyMembershipEndDate)
31
+
32
+ !has_end_date
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,224 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Person.
4
+ # rubocop:disable ModuleLength
5
+ module Person
6
+ # Alias personGivenName with fallback.
7
+ #
8
+ # @return [String, String] the given name of the Grom::Node or an empty string.
9
+ def given_name
10
+ respond_to?(:personGivenName) ? personGivenName : ''
11
+ end
12
+
13
+ # Alias personFamilyName with fallback.
14
+ #
15
+ # @return [String, String] the family name of the Grom::Node or an empty string.
16
+ def family_name
17
+ respond_to?(:personFamilyName) ? personFamilyName : ''
18
+ end
19
+
20
+ # Alias personOtherNames with fallback.
21
+ #
22
+ # @return [String, String] the other names of the Grom::Node or an empty string.
23
+ def other_name
24
+ respond_to?(:personOtherNames) ? personOtherNames : ''
25
+ end
26
+
27
+ # Alias personDateOfBirth with fallback.
28
+ #
29
+ # @return [DateTime, nil] the date of birth of the Grom::Node or nil.
30
+ def date_of_birth
31
+ respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil
32
+ end
33
+
34
+ # Builds a full name using personGivenName and personFamilyName.
35
+ #
36
+ # @return [String, String] the full name of the Grom::Node or an empty string.
37
+ def full_name
38
+ full_name = ''
39
+ full_name += respond_to?(:personGivenName) ? personGivenName + ' ' : ''
40
+ full_name += respond_to?(:personFamilyName) ? personFamilyName : ''
41
+ full_name.rstrip
42
+ end
43
+
44
+ # Alias memberHasIncumbency with fallback.
45
+ #
46
+ # @return [Array, Array] all the incumbencies of the Grom::Node or an empty array.
47
+ def incumbencies
48
+ respond_to?(:memberHasIncumbency) ? memberHasIncumbency : []
49
+ end
50
+
51
+ # Alias memberHasIncumbency with fallback.
52
+ #
53
+ # @return [Array, Array] the seat incumbencies of the Grom::Node or an empty array.
54
+ def seat_incumbencies
55
+ if respond_to?(:memberHasIncumbency)
56
+ memberHasIncumbency.select { |inc| inc.type == 'http://id.ukpds.org/schema/SeatIncumbency' }
57
+ else
58
+ []
59
+ end
60
+ end
61
+
62
+ # Alias memberHasIncumbency with fallback.
63
+ #
64
+ # @return [Array, Array] the house incumbencies of the Grom::Node or an empty array.
65
+ def house_incumbencies
66
+ if respond_to?(:memberHasIncumbency)
67
+ memberHasIncumbency.select { |inc| inc.type == 'http://id.ukpds.org/schema/HouseIncumbency' }
68
+ else
69
+ []
70
+ end
71
+ end
72
+
73
+ # Alias seatIncumbencyHasHouseSeat with fallback.
74
+ #
75
+ # @return [Array, Array] the seats of the Grom::Node or an empty array.
76
+ def seats
77
+ return @seats unless @seats.nil?
78
+
79
+ seats = []
80
+ seat_incumbencies.each do |incumbency|
81
+ seats << incumbency.seat if incumbency.respond_to?(:seat)
82
+ end
83
+
84
+ @seats = seats.flatten.uniq
85
+ end
86
+
87
+ # Alias houseSeatHasHouse with fallback.
88
+ #
89
+ # @return [Array, Array] the houses of the Grom::Node or an empty array.
90
+ def houses
91
+ return @houses unless @houses.nil?
92
+
93
+ houses = []
94
+ seats.each do |seat|
95
+ houses << seat.house
96
+ end
97
+
98
+ house_incumbencies.each do |inc|
99
+ houses << inc.house
100
+ end
101
+
102
+ @houses = houses.flatten.uniq
103
+ end
104
+
105
+ # Alias houseSeatHasConstituencyGroup with fallback.
106
+ #
107
+ # @return [Array, Array] the constituencies of the Grom::Node or an empty array.
108
+ def constituencies
109
+ return @constituencies unless @constituencies.nil?
110
+
111
+ constituencies = []
112
+ seats.each do |seat|
113
+ constituencies << seat.constituency
114
+ end
115
+
116
+ @constituencies = constituencies.flatten.uniq
117
+ end
118
+
119
+ # Alias partyMemberHasPartyMembership with fallback.
120
+ #
121
+ # @return [Array, Array] the party memberships of the Grom::Node or an empty array.
122
+ def party_memberships
123
+ respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
124
+ end
125
+
126
+ # Alias partyMembershipHasParty with fallback.
127
+ #
128
+ # @return [Array, Array] the parties of the Grom::Node or an empty array.
129
+ def parties
130
+ return @parties unless @parties.nil?
131
+
132
+ parties = []
133
+ party_memberships.each do |party_membership|
134
+ parties << party_membership.party
135
+ end
136
+
137
+ @parties = parties.flatten.uniq.compact
138
+ end
139
+
140
+ # Alias personHasContactPoint with fallback.
141
+ #
142
+ # @return [Array, Array] the contact points of the Grom::Node or an empty array.
143
+ def contact_points
144
+ respond_to?(:personHasContactPoint) ? personHasContactPoint : []
145
+ end
146
+
147
+ # Alias personHasGenderIdentity with fallback.
148
+ #
149
+ # @return [Array, Array] the gender identities of the Grom::Node or an empty array.
150
+ def gender_identities
151
+ respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
152
+ end
153
+
154
+ # Alias genderIdentityHasGender with fallback.
155
+ #
156
+ # @return [Array, Array] the gender of the Grom::Node or nil.
157
+ def gender
158
+ gender_identities.empty? ? nil : gender_identities.first.gender
159
+ end
160
+
161
+ # Checks the statuses of the Grom::Node.
162
+ #
163
+ # @return [Hash, Hash] the statuses of the Grom::Node or an empty hash.
164
+ def statuses
165
+ return @statuses unless @statuses.nil?
166
+
167
+ statuses = {}
168
+ statuses[:house_membership_status] = house_membership_status
169
+ statuses[:general_membership_status] = general_membership_status
170
+
171
+ @statuses = statuses
172
+ end
173
+
174
+ # Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.
175
+ #
176
+ # @return [String, String] the full title of the Grom::Node or an empty string.
177
+ def full_title
178
+ respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : ''
179
+ end
180
+
181
+ # Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
182
+ #
183
+ # @return [String, String] the display name of the Grom::Node or the full name.
184
+ def display_name
185
+ respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name
186
+ end
187
+
188
+ # Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.
189
+ #
190
+ # @return [String, String] the sort name of the Grom::Node or an empty string.
191
+ def sort_name
192
+ respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : ''
193
+ end
194
+
195
+ private
196
+
197
+ def house_membership_status
198
+ no_current_seat_incumbency = seat_incumbencies.select(&:current?).empty?
199
+ no_current_house_incumbency = house_incumbencies.select(&:current?).empty?
200
+ former_lord = (!house_incumbencies.empty? && no_current_house_incumbency)
201
+ former_mp = (!seat_incumbencies.empty? && no_current_seat_incumbency)
202
+
203
+ build_house_membership_status(no_current_seat_incumbency, no_current_house_incumbency, former_lord, former_mp)
204
+ end
205
+
206
+ def build_house_membership_status(no_current_seat_incumbency, no_current_house_incumbency, former_lord, former_mp)
207
+ statuses = []
208
+ statuses << 'Current MP' unless no_current_seat_incumbency
209
+ statuses << 'Lord' unless no_current_house_incumbency
210
+ statuses << 'Former Lord' if former_lord
211
+ statuses << 'Former MP' if former_mp
212
+
213
+ statuses
214
+ end
215
+
216
+ def general_membership_status
217
+ statuses = []
218
+ statuses << 'Current Member' unless incumbencies.select(&:current?).empty?
219
+ statuses << 'Former Member' if !incumbencies.empty? && incumbencies.select(&:current?).empty?
220
+ statuses
221
+ end
222
+ end
223
+ end
224
+ end