parliament-ruby 0.5.19 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -3
- data/.travis.yml +0 -1
- data/Gemfile +2 -0
- data/Makefile +9 -4
- data/README.md +185 -11
- data/Rakefile +1 -1
- data/lib/parliament/client_error.rb +21 -0
- data/lib/parliament/decorator/constituency_area.rb +27 -0
- data/lib/parliament/{decorators → decorator}/constituency_group.rb +29 -1
- data/lib/parliament/decorator/contact_point.rb +48 -0
- data/lib/parliament/decorator/gender.rb +13 -0
- data/lib/parliament/decorator/gender_identity.rb +13 -0
- data/lib/parliament/decorator/house.rb +41 -0
- data/lib/parliament/decorator/house_incumbency.rb +50 -0
- data/lib/parliament/decorator/house_seat.rb +27 -0
- data/lib/parliament/decorator/incumbency.rb +57 -0
- data/lib/parliament/decorator/party.rb +27 -0
- data/lib/parliament/decorator/party_membership.rb +36 -0
- data/lib/parliament/decorator/person.rb +224 -0
- data/lib/parliament/{decorators → decorator}/postal_address.rb +5 -1
- data/lib/parliament/decorator/seat_incumbency.rb +64 -0
- data/lib/parliament/decorator.rb +7 -0
- data/lib/parliament/network_error.rb +13 -0
- data/lib/parliament/no_content_response_error.rb +19 -0
- data/lib/parliament/request.rb +112 -33
- data/lib/parliament/response.rb +76 -9
- data/lib/parliament/server_error.rb +21 -0
- data/lib/parliament/utils.rb +113 -13
- data/lib/parliament/version.rb +1 -1
- data/lib/parliament.rb +8 -4
- data/parliament-ruby.gemspec +6 -6
- metadata +32 -28
- data/lib/parliament/decorators/constituency_area.rb +0 -17
- data/lib/parliament/decorators/contact_point.rb +0 -29
- data/lib/parliament/decorators/gender.rb +0 -9
- data/lib/parliament/decorators/gender_identity.rb +0 -9
- data/lib/parliament/decorators/house.rb +0 -28
- data/lib/parliament/decorators/house_incumbency.rb +0 -31
- data/lib/parliament/decorators/house_seat.rb +0 -17
- data/lib/parliament/decorators/incumbency.rb +0 -35
- data/lib/parliament/decorators/party.rb +0 -17
- data/lib/parliament/decorators/party_membership.rb +0 -23
- data/lib/parliament/decorators/person.rb +0 -152
- data/lib/parliament/decorators/seat_incumbency.rb +0 -39
- data/lib/parliament/no_content_error.rb +0 -9
@@ -1,17 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module HouseSeat
|
4
|
-
def house
|
5
|
-
respond_to?(:houseSeatHasHouse) ? houseSeatHasHouse.first : nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def constituency
|
9
|
-
respond_to?(:houseSeatHasConstituencyGroup) ? houseSeatHasConstituencyGroup.first : nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def seat_incumbencies
|
13
|
-
respond_to?(:houseSeatHasSeatIncumbency) ? houseSeatHasSeatIncumbency : []
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module Incumbency
|
4
|
-
def start_date
|
5
|
-
respond_to?(:incumbencyStartDate) ? DateTime.parse(incumbencyStartDate) : nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def end_date
|
9
|
-
respond_to?(:incumbencyEndDate) ? DateTime.parse(incumbencyEndDate) : nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def current?
|
13
|
-
has_end_date = respond_to?(:incumbencyEndDate)
|
14
|
-
|
15
|
-
!has_end_date
|
16
|
-
end
|
17
|
-
|
18
|
-
def member
|
19
|
-
respond_to?(:incumbencyHasMember) ? incumbencyHasMember.first : nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def contact_points
|
23
|
-
respond_to?(:incumbencyHasContactPoint) ? incumbencyHasContactPoint : []
|
24
|
-
end
|
25
|
-
|
26
|
-
def seat
|
27
|
-
respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def house
|
31
|
-
respond_to?(:houseIncumbencyHasHouse) ? houseIncumbencyHasHouse.first : nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module Party
|
4
|
-
def name
|
5
|
-
respond_to?(:partyName) ? partyName : ''
|
6
|
-
end
|
7
|
-
|
8
|
-
def party_memberships
|
9
|
-
respond_to?(:partyHasPartyMembership) ? partyHasPartyMembership : []
|
10
|
-
end
|
11
|
-
|
12
|
-
def member_count
|
13
|
-
respond_to?(:count) ? count.to_i : nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module PartyMembership
|
4
|
-
def party
|
5
|
-
respond_to?(:partyMembershipHasParty) ? partyMembershipHasParty.first : nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def start_date
|
9
|
-
respond_to?(:partyMembershipStartDate) ? DateTime.parse(partyMembershipStartDate) : nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def end_date
|
13
|
-
respond_to?(:partyMembershipEndDate) ? DateTime.parse(partyMembershipEndDate) : nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def current?
|
17
|
-
has_end_date = respond_to?(:partyMembershipEndDate)
|
18
|
-
|
19
|
-
!has_end_date
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module Person
|
4
|
-
def given_name
|
5
|
-
respond_to?(:personGivenName) ? personGivenName : ''
|
6
|
-
end
|
7
|
-
|
8
|
-
def family_name
|
9
|
-
respond_to?(:personFamilyName) ? personFamilyName : ''
|
10
|
-
end
|
11
|
-
|
12
|
-
def other_name
|
13
|
-
respond_to?(:personOtherNames) ? personOtherNames : ''
|
14
|
-
end
|
15
|
-
|
16
|
-
def date_of_birth
|
17
|
-
respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil
|
18
|
-
end
|
19
|
-
|
20
|
-
def full_name
|
21
|
-
full_name = ''
|
22
|
-
full_name += respond_to?(:personGivenName) ? personGivenName + ' ' : ''
|
23
|
-
full_name += respond_to?(:personFamilyName) ? personFamilyName : ''
|
24
|
-
full_name.rstrip
|
25
|
-
end
|
26
|
-
|
27
|
-
def incumbencies
|
28
|
-
respond_to?(:memberHasIncumbency) ? memberHasIncumbency : []
|
29
|
-
end
|
30
|
-
|
31
|
-
def seat_incumbencies
|
32
|
-
if respond_to?(:memberHasIncumbency)
|
33
|
-
memberHasIncumbency.select { |inc| inc.type == 'http://id.ukpds.org/schema/SeatIncumbency' }
|
34
|
-
else
|
35
|
-
[]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def house_incumbencies
|
40
|
-
if respond_to?(:memberHasIncumbency)
|
41
|
-
memberHasIncumbency.select { |inc| inc.type == 'http://id.ukpds.org/schema/HouseIncumbency' }
|
42
|
-
else
|
43
|
-
[]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def seats
|
48
|
-
return @seats unless @seats.nil?
|
49
|
-
|
50
|
-
seats = []
|
51
|
-
seat_incumbencies.each do |incumbency|
|
52
|
-
seats << incumbency.seat if incumbency.respond_to?(:seat)
|
53
|
-
end
|
54
|
-
|
55
|
-
@seats = seats.flatten.uniq
|
56
|
-
end
|
57
|
-
|
58
|
-
def houses
|
59
|
-
return @houses unless @houses.nil?
|
60
|
-
|
61
|
-
houses = []
|
62
|
-
seats.each do |seat|
|
63
|
-
houses << seat.house
|
64
|
-
end
|
65
|
-
|
66
|
-
house_incumbencies.each do |inc|
|
67
|
-
houses << inc.house
|
68
|
-
end
|
69
|
-
|
70
|
-
@houses = houses.flatten.uniq
|
71
|
-
end
|
72
|
-
|
73
|
-
def constituencies
|
74
|
-
return @constituencies unless @constituencies.nil?
|
75
|
-
|
76
|
-
constituencies = []
|
77
|
-
seats.each do |seat|
|
78
|
-
constituencies << seat.constituency
|
79
|
-
end
|
80
|
-
|
81
|
-
@constituencies = constituencies.flatten.uniq
|
82
|
-
end
|
83
|
-
|
84
|
-
def party_memberships
|
85
|
-
respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
|
86
|
-
end
|
87
|
-
|
88
|
-
def parties
|
89
|
-
return @parties unless @parties.nil?
|
90
|
-
|
91
|
-
parties = []
|
92
|
-
party_memberships.each do |party_membership|
|
93
|
-
parties << party_membership.party
|
94
|
-
end
|
95
|
-
|
96
|
-
@parties = parties.flatten.uniq.compact
|
97
|
-
end
|
98
|
-
|
99
|
-
def contact_points
|
100
|
-
respond_to?(:personHasContactPoint) ? personHasContactPoint : []
|
101
|
-
end
|
102
|
-
|
103
|
-
def gender_identities
|
104
|
-
respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
|
105
|
-
end
|
106
|
-
|
107
|
-
def gender
|
108
|
-
gender_identities.empty? ? nil : gender_identities.first.gender
|
109
|
-
end
|
110
|
-
|
111
|
-
def statuses
|
112
|
-
return @statuses unless @statuses.nil?
|
113
|
-
|
114
|
-
statuses = {}
|
115
|
-
statuses[:house_membership_status] = house_membership_status
|
116
|
-
statuses[:general_membership_status] = general_membership_status
|
117
|
-
|
118
|
-
@statuses = statuses
|
119
|
-
end
|
120
|
-
|
121
|
-
def full_title
|
122
|
-
respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : ''
|
123
|
-
end
|
124
|
-
|
125
|
-
def display_name
|
126
|
-
respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name
|
127
|
-
end
|
128
|
-
|
129
|
-
def sort_name
|
130
|
-
respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : ''
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def house_membership_status
|
136
|
-
statuses = []
|
137
|
-
statuses << 'Current MP' unless seat_incumbencies.select(&:current?).empty?
|
138
|
-
statuses << 'Lord' unless house_incumbencies.select(&:current?).empty?
|
139
|
-
statuses << 'Former Lord' if !house_incumbencies.empty? && house_incumbencies.select(&:current?).empty?
|
140
|
-
statuses << 'Former MP' if !seat_incumbencies.empty? && seat_incumbencies.select(&:current?).empty?
|
141
|
-
statuses
|
142
|
-
end
|
143
|
-
|
144
|
-
def general_membership_status
|
145
|
-
statuses = []
|
146
|
-
statuses << 'Current Member' unless incumbencies.select(&:current?).empty?
|
147
|
-
statuses << 'Former Member' if !incumbencies.empty? && incumbencies.select(&:current?).empty?
|
148
|
-
statuses
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Parliament
|
2
|
-
module Decorators
|
3
|
-
module SeatIncumbency
|
4
|
-
def start_date
|
5
|
-
respond_to?(:incumbencyStartDate) ? DateTime.parse(incumbencyStartDate) : nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def end_date
|
9
|
-
respond_to?(:incumbencyEndDate) ? DateTime.parse(incumbencyEndDate) : nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def seat
|
13
|
-
respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def current?
|
17
|
-
has_end_date = respond_to?(:incumbencyEndDate)
|
18
|
-
|
19
|
-
!has_end_date
|
20
|
-
end
|
21
|
-
|
22
|
-
def house
|
23
|
-
seat.nil? ? nil : seat.house
|
24
|
-
end
|
25
|
-
|
26
|
-
def constituency
|
27
|
-
seat.nil? ? nil : seat.constituency
|
28
|
-
end
|
29
|
-
|
30
|
-
def contact_points
|
31
|
-
respond_to?(:incumbencyHasContactPoint) ? incumbencyHasContactPoint : []
|
32
|
-
end
|
33
|
-
|
34
|
-
def member
|
35
|
-
respond_to?(:incumbencyHasMember) ? incumbencyHasMember.first : nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|