parliament-ruby 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 723becb108a322e281da7b1caf864791ed4707ba
4
- data.tar.gz: 26f7be8681949436953d83d45e4fddffb5044149
3
+ metadata.gz: fbf1462f8c45035775444da6cbb76f8dfd49a905
4
+ data.tar.gz: 3fc840d1285f95774e4c1d6b7bc496707dd1ed5f
5
5
  SHA512:
6
- metadata.gz: bdcb1face1f18f79a9acf84c73673bde3aa7df4c1fa1fd279e253d2c891770fc97ddab9c75b4aa9c3c29c2cf92b35886bbfb196077be238cd527f2f06de3dda1
7
- data.tar.gz: 2d86fbfdd19c45e0289900aa4381c89d983c11635ecf07ef0dba31640c6493dd4a3bb5b00b1cfd5812945975dd35cf2a3d67a1fb79541d2250474d1c6379d924
6
+ metadata.gz: 161013d67753e2b47ce04633355047795bad91d3505513c18afe3ba6ba670ac24e94cde0adc6370037de8cc8dfcb4ac7dfc064b706fa29ee8d3a743522fd0b6f
7
+ data.tar.gz: 0015226bef6ee2c28a9f4908fcb3166422bd28ebe300f9447f3bf2d21e78cdccf7986cfae1e27ee7e1880df14e953c38b7e93790d788afd59eeb438c529cd0df
data/lib/parliament.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  require 'net/http'
3
2
  require 'grom'
4
3
 
@@ -6,6 +5,9 @@ require 'parliament/version'
6
5
  require 'parliament/request'
7
6
  require 'parliament/response'
8
7
 
8
+ # require all the decorators
9
+ Dir[File.join(File.dirname(__FILE__), 'parliament/decorators', '*.rb')].each { |decorator| require decorator }
10
+
9
11
  module Parliament
10
12
  # Your code goes here...
11
13
  end
@@ -0,0 +1,17 @@
1
+ module Parliament
2
+ module Decorators
3
+ module ConstituencyArea
4
+ def latitude
5
+ respond_to?(:constituencyAreaLatitude) ? constituencyAreaLatitude : ''
6
+ end
7
+
8
+ def longitude
9
+ respond_to?(:constituencyAreaLongitude) ? constituencyAreaLongitude : ''
10
+ end
11
+
12
+ def polygon
13
+ respond_to?(:constituencyAreaExtent) ? constituencyAreaExtent : ''
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ module Parliament
2
+ module Decorators
3
+ module ConstituencyGroup
4
+ def name
5
+ respond_to?(:constituencyGroupName) ? constituencyGroupName : ''
6
+ end
7
+
8
+ def start_date
9
+ respond_to?(:constituencyGroupStartDate) ? constituencyGroupStartDate : ''
10
+ end
11
+
12
+ def end_date
13
+ respond_to?(:constituencyGroupEndDate) ? constituencyGroupEndDate : ''
14
+ end
15
+
16
+ def seats
17
+ respond_to?(:constituencyGroupHasHouseSeat) ? constituencyGroupHasHouseSeat : []
18
+ end
19
+
20
+ def seat_incumbencies
21
+ return @seat_incumbencies unless @seat_incumbencies.nil?
22
+
23
+ seat_incumbencies = []
24
+ seats.each do |seat|
25
+ seat_incumbencies << seat.seat_incumbencies
26
+ end
27
+
28
+ @seat_incumbencies = seat_incumbencies.flatten.uniq
29
+ end
30
+
31
+ def members
32
+ return @members unless @members .nil?
33
+
34
+ members = []
35
+ seat_incumbencies.each do |seat_incumbency|
36
+ members << seat_incumbency.member
37
+ end
38
+
39
+ @members = members.flatten.uniq
40
+ end
41
+
42
+ def area
43
+ respond_to?(:constituencyGroupHasConstituencyArea) ? constituencyGroupHasConstituencyArea.first : nil
44
+ end
45
+
46
+ def contact_points
47
+ return @contact_points unless @contact_points.nil?
48
+
49
+ contact_points = []
50
+ seat_incumbencies.each do |seat_incumbency|
51
+ contact_points << seat_incumbency.contact_points
52
+ end
53
+
54
+ @contact_points = contact_points.flatten.uniq
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ module Parliament
2
+ module Decorators
3
+ module ContactPoint
4
+ def postal_addresses
5
+ respond_to?(:contactPointHasPostalAddress) ? contactPointHasPostalAddress : []
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Parliament
2
+ module Decorators
3
+ module Gender
4
+ def name
5
+ respond_to?(:genderName) ? genderName : ''
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Parliament
2
+ module Decorators
3
+ module GenderIdentity
4
+ def gender
5
+ respond_to?(:genderIdentityHasGender) ? genderIdentityHasGender.first : nil
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Parliament
2
+ module Decorators
3
+ module House
4
+ def name
5
+ respond_to?(:houseName) ? houseName : ''
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,14 @@
1
+
2
+ module Parliament
3
+ module Decorators
4
+ module Party
5
+ def name
6
+ respond_to?(:partyName) ? partyName : ''
7
+ end
8
+
9
+ def party_memberships
10
+ respond_to?(:partyHasPartyMembership) ? partyHasPartyMembership : []
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
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) ? partyMembershipStartDate : ''
10
+ end
11
+
12
+ def end_date
13
+ respond_to?(:partyMembershipEndDate) ? partyMembershipEndDate : ''
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,92 @@
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) ? personDateOfBirth : ''
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 seat_incumbencies
28
+ respond_to?(:memberHasSeatIncumbency) ? memberHasSeatIncumbency : []
29
+ end
30
+
31
+ def seats
32
+ return @seats unless @seats.nil?
33
+
34
+ seats = []
35
+ seat_incumbencies.each do |seat_incumbency|
36
+ seats << seat_incumbency.seat
37
+ end
38
+
39
+ @seats = seats.flatten.uniq
40
+ end
41
+
42
+ def houses
43
+ return @houses unless @houses.nil?
44
+
45
+ houses = []
46
+ seats.each do |seat|
47
+ houses << seat.house
48
+ end
49
+
50
+ @houses = houses.flatten.uniq
51
+ end
52
+
53
+ def constituencies
54
+ return @constituencies unless @constituencies.nil?
55
+
56
+ constituencies = []
57
+ seats.each do |seat|
58
+ constituencies << seat.constituency
59
+ end
60
+
61
+ @constituencies = constituencies.flatten.uniq
62
+ end
63
+
64
+ def party_memberships
65
+ respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
66
+ end
67
+
68
+ def parties
69
+ return @parties unless @parties.nil?
70
+
71
+ parties = []
72
+ party_memberships.each do |party_membership|
73
+ parties << party_membership.party
74
+ end
75
+
76
+ @parties = parties.flatten.uniq.compact
77
+ end
78
+
79
+ def contact_points
80
+ respond_to?(:personHasContactPoint) ? personHasContactPoint : []
81
+ end
82
+
83
+ def gender_identities
84
+ respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
85
+ end
86
+
87
+ def gender
88
+ gender_identities.empty? ? nil : gender_identities.first.gender
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,22 @@
1
+ module Parliament
2
+ module Decorators
3
+ module PostalAddress
4
+ def full_address
5
+ address_array.join(', ')
6
+ end
7
+
8
+ private
9
+
10
+ def address_array
11
+ address_array = []
12
+ (1..5).each do |i|
13
+ if respond_to?("addressLine#{i}".to_sym)
14
+ address_array << instance_variable_get("@addressLine#{i}".to_sym)
15
+ end
16
+ end
17
+ address_array << postCode if respond_to?(:postCode)
18
+ address_array
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module Parliament
2
+ module Decorators
3
+ module SeatIncumbency
4
+ def start_date
5
+ respond_to?(:seatIncumbencyStartDate) ? seatIncumbencyStartDate : ''
6
+ end
7
+
8
+ def end_date
9
+ respond_to?(:seatIncumbencyEndDate) ? seatIncumbencyEndDate : ''
10
+ end
11
+
12
+ def seat
13
+ respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
14
+ end
15
+
16
+ def member
17
+ respond_to?(:seatIncumbencyHasMember) ? seatIncumbencyHasMember.first : nil
18
+ end
19
+
20
+ def current?
21
+ has_end_date = respond_to?(:seatIncumbencyEndDate)
22
+
23
+ !has_end_date
24
+ end
25
+
26
+ def house
27
+ seat.nil? ? nil : seat.house
28
+ end
29
+
30
+ def constituency
31
+ seat.nil? ? nil : seat.constituency
32
+ end
33
+
34
+ def contact_points
35
+ respond_to?(:seatIncumbencyHasContactPoint) ? seatIncumbencyHasContactPoint : []
36
+ end
37
+ end
38
+ end
39
+ end
@@ -27,7 +27,17 @@ module Parliament
27
27
  raise StandardError, 'This is a HTTPClientError' if response.is_a?(Net::HTTPClientError)
28
28
  raise StandardError, 'This is a HTTPServerError' if response.is_a?(Net::HTTPServerError)
29
29
 
30
- Parliament::Response.new(Grom::Reader.new(response.body).objects)
30
+ objects = Grom::Reader.new(response.body).objects
31
+ objects.map { |object| assign_decorator(object) }
32
+
33
+ Parliament::Response.new(objects)
34
+ end
35
+
36
+ def assign_decorator(object)
37
+ object_type = Grom::Helper.get_id(object.type)
38
+ return object unless Parliament::Decorators.constants.include?(object_type.to_sym)
39
+ decorator_module = Object.const_get("Parliament::Decorators::#{object_type}")
40
+ object.extend(decorator_module)
31
41
  end
32
42
 
33
43
  private
@@ -5,7 +5,7 @@ module Parliament
5
5
  include Enumerable
6
6
  extend Forwardable
7
7
  attr_reader :nodes
8
- def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length
8
+ def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length, :[]
9
9
 
10
10
  def initialize(nodes)
11
11
  @nodes = nodes
@@ -1,3 +1,3 @@
1
1
  module Parliament
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -21,15 +21,15 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'grom', '~> 0.2.0'
24
+ spec.add_dependency 'grom', '~> 0.3.5'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.13'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
29
  spec.add_development_dependency 'rubocop', '~> 0.47.1'
30
- spec.add_development_dependency 'pry', '~> 0.10.4'
31
- spec.add_development_dependency 'pry-nav', '~> 0.2.4'
32
30
  spec.add_development_dependency 'simplecov', '~> 0.12.0'
33
31
  spec.add_development_dependency 'vcr', '~> 3.0.3'
34
32
  spec.add_development_dependency 'webmock', '~> 2.3.2'
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'pry-nav'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Rayner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-25 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grom
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.3.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.3.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,75 +81,75 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.47.1
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.10.4
89
+ version: 0.12.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.10.4
96
+ version: 0.12.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry-nav
98
+ name: vcr
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.2.4
103
+ version: 3.0.3
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.2.4
110
+ version: 3.0.3
111
111
  - !ruby/object:Gem::Dependency
112
- name: simplecov
112
+ name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.12.0
117
+ version: 2.3.2
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.12.0
124
+ version: 2.3.2
125
125
  - !ruby/object:Gem::Dependency
126
- name: vcr
126
+ name: pry
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 3.0.3
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 3.0.3
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: webmock
140
+ name: pry-nav
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 2.3.2
145
+ version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 2.3.2
152
+ version: '0'
153
153
  description: Internal parliamentary data API wrapper for ruby
154
154
  email:
155
155
  - mattrayner1@gmail.com
@@ -157,7 +157,6 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
- - ".bash_profile"
161
160
  - ".gitignore"
162
161
  - ".hound.yml"
163
162
  - ".rspec"
@@ -172,6 +171,18 @@ files:
172
171
  - bin/console
173
172
  - bin/setup
174
173
  - lib/parliament.rb
174
+ - lib/parliament/decorators/constituency_area.rb
175
+ - lib/parliament/decorators/constituency_group.rb
176
+ - lib/parliament/decorators/contact_point.rb
177
+ - lib/parliament/decorators/gender.rb
178
+ - lib/parliament/decorators/gender_identity.rb
179
+ - lib/parliament/decorators/house.rb
180
+ - lib/parliament/decorators/house_seat.rb
181
+ - lib/parliament/decorators/party.rb
182
+ - lib/parliament/decorators/party_membership.rb
183
+ - lib/parliament/decorators/person.rb
184
+ - lib/parliament/decorators/postal_address.rb
185
+ - lib/parliament/decorators/seat_incumbency.rb
175
186
  - lib/parliament/request.rb
176
187
  - lib/parliament/response.rb
177
188
  - lib/parliament/version.rb
@@ -196,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
207
  version: '0'
197
208
  requirements: []
198
209
  rubyforge_project:
199
- rubygems_version: 2.6.6
210
+ rubygems_version: 2.5.1
200
211
  signing_key:
201
212
  specification_version: 4
202
213
  summary: Internal parliamentary data API wrapper for ruby
data/.bash_profile DELETED
@@ -1 +0,0 @@
1
- alias be='bundle exec'