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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e992a0e8626c4a188ab4b3bff46dff2f0a6c8e7f
4
- data.tar.gz: aacaa9952878ee6e6735cf4699ed587e32e3dbb7
3
+ metadata.gz: 792a61423210db4d06e2690193e47bc5949ffc6b
4
+ data.tar.gz: e0649c47b1ba552d2045cbbde8f37c26ab6365c1
5
5
  SHA512:
6
- metadata.gz: 31a11f36cb3f29e87e037caa5a07456d66c8bacc829ed07cb581f38fb03841f2f5c806bd23775a2de0dbe22d247925dd19b347d432079bed59980ba3d0c0a84b
7
- data.tar.gz: a1ae6ee4be3375e83170a9b623281640683ad2e25249165c551d02f93ca20b7ce658c7a5741fc046af7ec82ce72420ea30fcb3e9ceace118fa70c5540fb8aa66
6
+ metadata.gz: c790934d4d403ec1e1a06af7d22c81eb7dea09dcaacc98b2c085ff2025f5ca0aa462c5ae8c2e35b00277e1527b26ee272e45fe5ca1b7e06c93733c03db73c831
7
+ data.tar.gz: c208d4dab4609203665386c20995500830a88bbae85ff8fe7dbee2aa91d3f457cbc9088ae81b00d1754040b47e66095c1b77142f48e482062850cc5b04544dea
data/.rubocop.yml CHANGED
@@ -1,9 +1,7 @@
1
1
  Metrics/LineLength:
2
2
  Description: 'Limit lines to 120 characters.'
3
3
  Max: 120
4
-
5
- Style/Documentation:
6
- Enabled: false
4
+ IgnoredPatterns: ['\A#', '\A([ ]{2}|[ ]{4})#']
7
5
 
8
6
  Style/SpaceBeforeFirstArg:
9
7
  Enabled: false
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.1
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  # Include coveralls for CI coverage reports
7
7
  gem 'coveralls', require: false
8
+
9
+ gem 'pry'
data/Makefile CHANGED
@@ -1,8 +1,13 @@
1
1
  test:
2
- bundle exec rspec spec
2
+ bundle exec rake
3
3
 
4
4
  build:
5
- gem build parliament-ruby.gemspec
5
+ gem build parliament-ruby.gemspec
6
+
7
+ release: build test
8
+ gem push parliament-ruby-*.gem
9
+ rm parliament-ruby-*.gem
10
+
11
+
12
+
6
13
 
7
- release: build test
8
- gem push parliament-ruby-*.gem ; rm parliament-ruby-*.gem
data/README.md CHANGED
@@ -16,7 +16,15 @@
16
16
  - [Setting up a connection](#setting-up-a-connection)
17
17
  - [Setting a base URL 'globally'](#setting-a-base-url-globally)
18
18
  - [Building an 'endpoint'](#building-an-endpoint)
19
- - [What's #get?](#whats-get)
19
+ - [Methods](#methods)
20
+ - [`#get`](#get)
21
+ - [`#filter`](#filter)
22
+ - [`#sort_by`](#sort_by)
23
+ - [`#reverse_sort_by`](#reverse_sort_by)
24
+ - [`Partliament::Utils`](#partliamentutils)
25
+ - [Methods](#methods-1)
26
+ - [`Parliament::Utils.sort_by`](#parliamentutilssort_by)
27
+ - [`Parliament::Utils.reverse_sort_by`](#parliamentutilsreverse_sort_by)
20
28
  - [Getting Started with Development](#getting-started-with-development)
21
29
  - [Running the tests](#running-the-tests)
22
30
  - [Contributing](#contributing)
@@ -41,6 +49,8 @@ gem 'parliament', git: 'https://github.com/ukparliament/parliament-ruby.git', br
41
49
  ## Usage
42
50
  This gem's main function is fetching an n-triple file from a remote server and converting it into linked ruby objects.
43
51
 
52
+ > **Note:** Comprehensive class documentation can be found on [rubydocs][rubydocs].
53
+
44
54
  ### Setting up a connection
45
55
  In order to connect to a remote server, we first need to set a base_url value, from which we will build an 'endpoint'. The base_url should be the beginning of a url without the trailing slash. For example `http://example.com` instead of `http://example.com/`.
46
56
  ```ruby
@@ -76,20 +86,182 @@ An endpoint is effectively just a full URL to an n-triple file on a remote serve
76
86
 
77
87
  Building an endpoint is simple, once you have a Parliament::Request object, you do something like this:
78
88
  ```ruby
79
- parliament = Parliament::Request.new(base_url: 'http://test.com') #=> #<Parliament::Request>
89
+ parliament = Parliament::Request.new(base_url: 'http://test.com') #=> #<Parliament::Request [...]>
90
+
91
+ # Target endpoint: 'http://test.com/parties/current'
92
+ parliament.parties.current
93
+
94
+ # Target endpoint: 'http://test.com/parties/123/people/current'
95
+ parliament.parties('123').people.current
96
+
97
+ # Target endpoint: 'http://test.com/people/123/letters/456'
98
+ parliament.people('123').letters('456')
99
+ ```
100
+
101
+
102
+ ### Methods
103
+ [parliament-ruby][parliament-ruby] comes with the following common methods:
104
+
105
+ | Method | Description |
106
+ |----------------------------------------|-------------|
107
+ | [`#get`](#get) | **Make a GET request** - Make a HTTP GET request to the endpoint we have built, and create Ruby objects. |
108
+ | [`#filter`](#filter) | **Filter the response** - After making a GET request, filter the objects returned by type attribute. |
109
+ | [`#sort_by`](#sort_by) | **Sort the response (ASC)** - After making a GET request, sort the result in ascending order. |
110
+ | [`#reverse_sort_by`](#reverse_sort_by) | **Sort the response (DESC)** - After making a GET request, sort the result in descending order. |
111
+
112
+ > **Note:** Comprehensive class documentation can be found on [rubydocs][rubydocs].
113
+
114
+ #### `#get`
115
+ Once you've built your endpoint (`parliament.people.current`), we use the `#get` method to tell us you're ready to get the data.
116
+
117
+ ```ruby
118
+ # Target endpoint: 'http://test.com/people/123/letters/456'
119
+ response = parliament.people('123').letters('456').get #=> #<Parliament::Response [...]>
120
+
121
+ response.each do |node|
122
+ # If your n-triple file contains a literal object it is stored into an instance variable accessible via the predicate
123
+ # name. For example, with the following triple:
124
+ # <http://id.ukpds.org/1234> <http://id.ukpds.org/schema/name> 'Matthew Rayner' .
125
+ #
126
+ # You would be able to access the `name` attribute like so:
127
+ puts node.name #=> 'Matthew Rayner'
128
+
129
+ # If your n-triple file contains a triple who's object is a URI, and that URI is defined within your file, a link will
130
+ # be created, allowing you to 'connect' the two objects. For example, with the following triples:
131
+ # <http://id.ukpds.org/1234> <http://id.ukpds.org/schema/name> 'Matthew Rayner' .
132
+ # <http://id.ukpds.org/1234> <http://id.ukpds.org/schema/partyMembership> <http://id.ukpds.org/5678> .
133
+ # <http://id.ukpds.org/5678> <http://id.ukpds.org/schema/startDate> "1992-04-09"^^<http://www.w3.org/2001/XMLSchema#date> .
134
+ #
135
+ # You would be able to access the start date attribute on the linked object like so:
136
+ puts node.graph_id #=> '12345'
137
+ puts node.name #=> 'Matthew Rayner'
138
+ puts node.partyMembership #=> [#<Grom::Node @startDate=...>]
139
+
140
+ puts node.partyMembership.first.startDate #=> "1992-04-09"
141
+ end
142
+ ```
143
+
144
+ `#get` returns a `Parliament::Response` object which contains all of the nodes from our n-triple response.
145
+
146
+ #### `#filter`
147
+ If your n-triple file contains a number of different objects you can filter based on type attribute.
148
+
149
+ ```ruby
150
+ # Target endpoint: 'http://test.com/people/members/current'
151
+ response = parliament.people.members.current.get #=> #<Parliament::Response [...]>
152
+
153
+ # Given the below set of triples, you will be able to filter on 'type' attribute.
154
+ # <http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
155
+ # <http://id.ukpds.org/4ef6c7b7-a5c8-4dde-a5a5-29c9f80d8a27> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Constituency> .
156
+ # <http://id.ukpds.org/80234c90-f86a-4942-b6ae-d1e57a0b378d> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Party> .
157
+ # <http://id.ukpds.org/HouseOfCommons> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/House> .
158
+ #
159
+ # The filter method returns an array of filtered responses. Each response holding just items with the given type attribute.
160
+ filtered_responses = response.filter('http://id.ukpds.org/schema/Person', 'http://id.ukpds.org/schema/Party', 'http://id.ukpds.org/schema/Constituency')
161
+ filtered_responses #=> [<#Parliament::Response [...]>, <#Parliament::Response []>, <#Parliament::Response [...]>]
162
+ ```
80
163
 
81
- # target endpoint: 'http://test.com/parties/current'
82
- parliament.parties.current.get
164
+ #### `#sort_by`
165
+ Once you have a `Parliament::Response` object, you can perform an ascending sort on the results by using the `#sort_by` method.
83
166
 
84
- # target endpoint: 'http://test.com/parties/123/people/current'
85
- parliament.parties('123').people.current.get
167
+ > **`#sort_by`** is an ascending order sort i.e. (a..z, 0..9)
86
168
 
87
- # target endpoint: 'http://test.com/people/123/letters/456'
88
- parliament.people('123').letters('456').get
169
+ ```ruby
170
+ # Target endpoint: 'http://test.com/people/members/current'
171
+ response = parliament.people.members.current.get #=> #<Parliament::Response [...]>
172
+
173
+ # Given the below set of triples, you can sort ascending like so:
174
+ # <http://id.ukpds.org/1234> <http://id.ukpds.org/schema/startDate> "1997-01-01"^^<http://www.w3.org/2001/XMLSchema#date> .
175
+ # <http://id.ukpds.org/5678> <http://id.ukpds.org/schema/startDate> "1991-03-15"^^<http://www.w3.org/2001/XMLSchema#date> .
176
+ # <http://id.ukpds.org/9101> <http://id.ukpds.org/schema/startDate> "2011-09-04"^^<http://www.w3.org/2001/XMLSchema#date> .
177
+ # <http://id.ukpds.org/1121> <http://id.ukpds.org/schema/startDate> "1981-07-31"^^<http://www.w3.org/2001/XMLSchema#date> .
178
+ # <http://id.ukpds.org/3141> <http://id.ukpds.org/schema/endDate> "1997-07-31"^^<http://www.w3.org/2001/XMLSchema#date> .
179
+ #
180
+ # The sort_by method returns a sorted array of Grom::Nodes, sorted by one, or many, symbols passed to it.
181
+ sorted_response = response.sort_by(:startDate)
182
+
183
+ # Output each of the graph_id and startDate values
184
+ sorted_response.each { |node| puts "#{node.graph_id} - #{node.respond_to?(:startDate) ? node.startDate : 'undefined'}" }
185
+ # http://id.ukpds.org/3141 - undefined
186
+ # http://id.ukpds.org/1121 - 1981-07-31
187
+ # http://id.ukpds.org/5678 - 1991-03-15
188
+ # http://id.ukpds.org/1234 - 1997-01-01
189
+ # http://id.ukpds.org/9101 - 2011-09-04
190
+ ```
191
+
192
+ > **NOTE:** `#sort_by` places all `nil` responses at the start of the sort. For a more custom sort, take a look at `Parliament::Utils.sort_by`.
193
+
194
+ #### `#reverse_sort_by`
195
+ `#reverse_sort_by` simple implements `#sort_by` and calls `#reverse!` on the resulting array. The above example would become:
196
+
197
+ ```ruby
198
+ # http://id.ukpds.org/9101 - 2011-09-04
199
+ # http://id.ukpds.org/1234 - 1997-01-01
200
+ # http://id.ukpds.org/5678 - 1991-03-15
201
+ # http://id.ukpds.org/1121 - 1981-07-31
202
+ # http://id.ukpds.org/3141 - undefined
89
203
  ```
90
204
 
91
- #### What's #get?
92
- Once you've built your endpoint (`parliament.people.current`), we use the `#get` method to tell us you're finished building and ready to get the data.
205
+ ### `Partliament::Utils`
206
+ Included with [parliament-ruby][parliament-ruby] is `Parliament::Utils`. This module includes helper methods commonly used throughout parliament.uk.
207
+
208
+ #### Methods
209
+
210
+ | Method | Description |
211
+ |-------------------------------------------------------|-------------|
212
+ | [`#sort_by`](#parliamentutilssort_by) | **Sort an enumerable thing (ASC)** - An implementation of ruby's `#sort_by` method that allows nil sorts. |
213
+ | [`#reverse_sort_by`](#parliamentutilsreverse_sort_by) | **Sort an enumerable thing (DESC)** - Reverse the result of `Parliament::Utils.reverse_sort_by` |
214
+
215
+
216
+ ##### `Parliament::Utils.sort_by`
217
+ One of the common use cases we have is sorting objects by a date (e.g. seat incumbency end date) where an object without an end date is considered 'current' and should be sorted to the top (or bottom) of a list.
218
+
219
+ Because we working with graph databases, a node without an endDate simply has no method when converted to an object with [GROM][grom].
220
+
221
+ The `Parliament::Utils.sort_by` method takes a hash of options, detailed below:
222
+
223
+ ```ruby
224
+ response = parliament.people('123').get.filter('http://id.ukpds.org/schema/Person')
225
+
226
+ objects = response.first.incumbencies
227
+
228
+ options = {
229
+ list: objects, # An enumerable of objects (most commonly an Array)
230
+ parameters: [:endDate], # An array of actions which we will sort by
231
+ prepend_rejected: false # {optional default=true} Should any objects that are 'rejected' be prepended to the sorted list, or appended. i.e. where to put objects that don't respond to parameters provided
232
+ }
233
+
234
+ sorted_list = Parliament::Util.sort_by(options)
235
+
236
+ sorted_list.each { |incumbency| puts incumbency.respond_to?(:endDate) ? incumbency.endDate : 'Current' }
237
+ # http://id.ukpds.org/1121 - 1981-07-31
238
+ # http://id.ukpds.org/5678 - 1991-03-15
239
+ # http://id.ukpds.org/1234 - 1997-01-01
240
+ # http://id.ukpds.org/9101 - 2011-09-04
241
+ # http://id.ukpds.org/3141 - Current
242
+ ```
243
+
244
+ ##### `Parliament::Utils.reverse_sort_by`
245
+ This method, under the hood, calls `Parliament::Utils.sort_by` and runs `#reverse!` on the result.
246
+
247
+ Following the above example, and changing:
248
+ ```ruby
249
+ sorted_list = Parliament::Util.sort_by(options)
250
+ ```
251
+
252
+ to:
253
+ ```ruby
254
+ sorted_list = Parliament::Util.reverse_sort_by(options)
255
+ ```
256
+
257
+ should result in:
258
+ ```ruby
259
+ # http://id.ukpds.org/3141 - Current
260
+ # http://id.ukpds.org/9101 - 2011-09-04
261
+ # http://id.ukpds.org/1234 - 1997-01-01
262
+ # http://id.ukpds.org/5678 - 1991-03-15
263
+ # http://id.ukpds.org/1121 - 1981-07-31
264
+ ```
93
265
 
94
266
 
95
267
  ## Getting Started with Development
@@ -127,9 +299,11 @@ If you wish to submit a bug fix or feature, you can create a pull request and it
127
299
  [parliament-ruby]: https://github.com/ukparliament/parliament-ruby
128
300
  [pds]: https://www.parliament.uk/mps-lords-and-offices/offices/bicameral/parliamentary-digital-service/
129
301
  [ruby-version]: https://github.com/ukparliament/parliament-ruby/blob/master/.ruby-version
302
+ [grom]: https://github.com/ukparliament/grom
303
+ [rubydocs]: http://www.rubydoc.info/github/ukparliament/parliament-ruby/master/file/README.md
130
304
 
131
305
  [info-gem]: https://rubygems.org/gems/parliament-ruby
132
- [shield-gem]: https://img.shields.io/gem/v/formatador.svg
306
+ [shield-gem]: https://img.shields.io/gem/v/parliament-ruby.svg
133
307
 
134
308
  [info-travis]: https://travis-ci.org/ukparliament/parliament-ruby
135
309
  [shield-travis]: https://img.shields.io/travis/ukparliament/parliament-ruby.svg
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task default: :spec
6
+ task default: :spec
@@ -0,0 +1,21 @@
1
+ module Parliament
2
+ # An error raised when a 4xx status code is returned by Net::HTTP inside of Parliament::Request.
3
+ #
4
+ # @see Parliament::ServerError
5
+ #
6
+ # @since 0.6.0
7
+ class ClientError < Parliament::NetworkError
8
+ # @param [String] url the url that caused the Parliament::ClientError
9
+ # @param [Net::HTTPClientError] response the Net:HTTPClientError that caused the Parliament::ClientError
10
+ #
11
+ # @example Creating a Parliament::ClientError
12
+ # url = 'http://localhost:3030/foo/bar'
13
+ #
14
+ # response = Net::HTTP.get_response(URI(url))
15
+ #
16
+ # raise Parliament::ClientError.new(url, response) if response.is_a?(Net::HTTPClientError)
17
+ def initialize(url, response)
18
+ super
19
+ end
20
+ end
21
+ 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/ConstituencyArea
4
+ module ConstituencyArea
5
+ # Alias constituencyAreaLatitude with fallback.
6
+ #
7
+ # @return [String, String] the latitude of the Grom::Node or an empty string.
8
+ def latitude
9
+ respond_to?(:constituencyAreaLatitude) ? constituencyAreaLatitude : ''
10
+ end
11
+
12
+ # Alias constituencyAreaLongitude with fallback.
13
+ #
14
+ # @return [String, String] the longitude of the Grom::Node or an empty string.
15
+ def longitude
16
+ respond_to?(:constituencyAreaLongitude) ? constituencyAreaLongitude : ''
17
+ end
18
+
19
+ # Alias constituencyAreaExtent with fallback.
20
+ #
21
+ # @return [String, String] the polygon of the Grom::Node or an empty string.
22
+ def polygon
23
+ respond_to?(:constituencyAreaExtent) ? constituencyAreaExtent : ''
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,22 +1,38 @@
1
1
  module Parliament
2
- module Decorators
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/ConstituencyGroup
3
4
  module ConstituencyGroup
5
+ # Alias constituencyGroupName with fallback.
6
+ #
7
+ # @return [String, String] the name of the Grom::Node or an empty string.
4
8
  def name
5
9
  respond_to?(:constituencyGroupName) ? constituencyGroupName : ''
6
10
  end
7
11
 
12
+ # Alias constituencyGroupStartDate with fallback.
13
+ #
14
+ # @return [DateTime, nil] the start date of the Grom::Node or nil.
8
15
  def start_date
9
16
  respond_to?(:constituencyGroupStartDate) ? DateTime.parse(constituencyGroupStartDate) : nil
10
17
  end
11
18
 
19
+ # Alias constituencyGroupEndDate with fallback.
20
+ #
21
+ # @return [DateTime, nil] the end date of the Grom::Node or nil.
12
22
  def end_date
13
23
  respond_to?(:constituencyGroupEndDate) ? DateTime.parse(constituencyGroupEndDate) : nil
14
24
  end
15
25
 
26
+ # Alias constituencyGroupHasHouseSeat with fallback.
27
+ #
28
+ # @return [Array, Array] the house seats of the Grom::Node or an empty array.
16
29
  def seats
17
30
  respond_to?(:constituencyGroupHasHouseSeat) ? constituencyGroupHasHouseSeat : []
18
31
  end
19
32
 
33
+ # Alias houseSeatHasSeatIncumbency with fallback.
34
+ #
35
+ # @return [Array, Array] the seat incumbencies of the Grom::Node or an empty array.
20
36
  def seat_incumbencies
21
37
  return @seat_incumbencies unless @seat_incumbencies.nil?
22
38
 
@@ -28,6 +44,9 @@ module Parliament
28
44
  @seat_incumbencies = seat_incumbencies.flatten.uniq
29
45
  end
30
46
 
47
+ # Alias incumbencyHasMember with fallback.
48
+ #
49
+ # @return [Array, Array] the members of the Grom::Node or an empty array.
31
50
  def members
32
51
  return @members unless @members .nil?
33
52
 
@@ -39,10 +58,16 @@ module Parliament
39
58
  @members = members.flatten.uniq
40
59
  end
41
60
 
61
+ # Alias constituencyGroupHasConstituencyArea with fallback.
62
+ #
63
+ # @return [Grom::Node, nil] a Grom::Node with type http://id.ukpds.org/schema/ConstituencyArea or nil.
42
64
  def area
43
65
  respond_to?(:constituencyGroupHasConstituencyArea) ? constituencyGroupHasConstituencyArea.first : nil
44
66
  end
45
67
 
68
+ # Alias incumbencyHasContactPoint with fallback.
69
+ #
70
+ # @return [Array, Array] the contact points of the Grom::Node or an empty array.
46
71
  def contact_points
47
72
  return @contact_points unless @contact_points.nil?
48
73
 
@@ -54,6 +79,9 @@ module Parliament
54
79
  @contact_points = contact_points.flatten.uniq
55
80
  end
56
81
 
82
+ # Checks if Grom::Node has an end date.
83
+ #
84
+ # @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
57
85
  def current?
58
86
  has_end_date = respond_to?(:constituencyGroupEndDate)
59
87
 
@@ -0,0 +1,48 @@
1
+ module Parliament
2
+ module Decorator
3
+ # Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/ContactPoint
4
+ module ContactPoint
5
+ # Alias contactPointHasPostalAddress with fallback.
6
+ #
7
+ # @return [Array, Array] an array of the postal addresses for the Grom::Node or an empty array.
8
+ def postal_addresses
9
+ respond_to?(:contactPointHasPostalAddress) ? contactPointHasPostalAddress : []
10
+ end
11
+
12
+ # Alias email with fallback.
13
+ #
14
+ # @return [String, String] the email of the Grom::Node or an empty string.
15
+ def email
16
+ instance_variable_get('@email'.to_sym).nil? ? '' : instance_variable_get('@email'.to_sym)
17
+ end
18
+
19
+ # Alias phoneNumber with fallback.
20
+ #
21
+ # @return [String, String] the phone number of the Grom::Node or an empty string.
22
+ def phone_number
23
+ respond_to?(:phoneNumber) ? phoneNumber : ''
24
+ end
25
+
26
+ # Alias faxNumber with fallback.
27
+ #
28
+ # @return [String, String] the fax number of the Grom::Node or an empty string.
29
+ def fax_number
30
+ respond_to?(:faxNumber) ? faxNumber : ''
31
+ end
32
+
33
+ # Alias contactPointHasPerson with fallback.
34
+ #
35
+ # @return [Array, Array] the person connected to the Grom::Node or an empty array.
36
+ def person
37
+ respond_to?(:contactPointHasPerson) ? contactPointHasPerson : []
38
+ end
39
+
40
+ # Alias contactPointHasIncumbency with fallback.
41
+ #
42
+ # @return [Grom::Node, nil] the incumbency of the Grom::Node or nil.
43
+ def incumbency
44
+ respond_to?(:contactPointHasIncumbency) ? contactPointHasIncumbency.first : nil
45
+ end
46
+ end
47
+ end
48
+ end