parliament-ruby 0.5.17 → 0.5.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b3c8c824743e8fc39a983cca382e33f4b60d51c
4
- data.tar.gz: 519ba032619e1efce25f5d1879257326bab01fec
3
+ metadata.gz: c3501f4829d180b5911b6c708883ea068a9f6fb6
4
+ data.tar.gz: c9b7f748e43e0ab6030e0b26bf4fee33937d5742
5
5
  SHA512:
6
- metadata.gz: e807d62ce5a058cc4aac67975d64040455af7a6e1583496f3f576e3cb70eeae5c2f675b64c2af0db3d0cf1a24d34f6bd293e7600cc29aa90a8e4719759bf951c
7
- data.tar.gz: 339d5a6f9ce41bfe1ff9cef9a75688d25e31a0d668307b73c18b4649f6c6e8565dadc8071978aa661aeca18da5cac0115e632f42db2790b75ea6295086fa147f
6
+ metadata.gz: 88f09fafba3a44800dffd57f58011e9c7eb3ba1ad9fb9cad43bf1fd3e0d816ce70c00d3b5b270c87f21ad6c0eae4d92c389cd095a2f71bbc1eedf3de6158e0c4
7
+ data.tar.gz: e8f14118976032573c758784e8ed0024a3cc19e4098fc90dba076402a059924bacf8ca40d81e4bf097d564e7fcf7401a4a4c0738861dd87941edc676c3cebc92
data/README.md CHANGED
@@ -72,7 +72,7 @@ Parliament::Request.new.base_url #=> 'http://example.com'
72
72
  ### Building an 'endpoint'
73
73
  Now that we have a `base_url` set, we will want to build an 'endpoint' such as: `http://test.com/parties/current`.
74
74
 
75
- An endpoint is effectively just a full URL to an n-triple file on a remote server..
75
+ An endpoint is effectively just a full URL to an n-triple file on a remote server.
76
76
 
77
77
  Building an endpoint is simple, once you have a Parliament::Request object, you do something like this:
78
78
  ```ruby
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -25,11 +25,7 @@ module Parliament
25
25
  end
26
26
 
27
27
  def incumbencies
28
- if respond_to?(:memberHasIncumbency)
29
- memberHasIncumbency.select { |inc| inc.type == 'http://id.ukpds.org/schema/Incumbency' }
30
- else
31
- []
32
- end
28
+ respond_to?(:memberHasIncumbency) ? memberHasIncumbency : []
33
29
  end
34
30
 
35
31
  def seat_incumbencies
@@ -36,20 +36,17 @@ module Parliament
36
36
  end
37
37
 
38
38
  def sort_by(*parameters)
39
- rejected = []
40
- grom_nodes = @nodes.dup
41
- grom_nodes.delete_if { |node| rejected << node unless parameters.all? { |param| node.respond_to?(param) } }
42
- grom_nodes.sort_by! do |node|
43
- parameters.map do |param|
44
- node.send(param).is_a?(String) ? I18n.transliterate(node.send(param)).downcase : node.send(param)
45
- end
46
- end
47
-
48
- rejected.concat(grom_nodes)
39
+ Parliament::Utils.sort_by({
40
+ list: @nodes,
41
+ parameters: parameters
42
+ })
49
43
  end
50
44
 
51
45
  def reverse_sort_by(*parameters)
52
- sort_by(*parameters).reverse!
46
+ Parliament::Utils.reverse_sort_by({
47
+ list: @nodes,
48
+ parameters: parameters
49
+ })
53
50
  end
54
51
  end
55
52
  end
@@ -0,0 +1,35 @@
1
+ module Parliament
2
+ module Utils
3
+ def self.sort_by(args)
4
+ rejected = []
5
+ args = sort_defaults.merge(args)
6
+ list = args[:list].dup
7
+ parameters = args[:parameters]
8
+
9
+ list.delete_if do |object|
10
+ rejected << object unless parameters.all? { |param| !object.send(param).nil? if object.respond_to?(param) }
11
+ end
12
+
13
+ list.sort_by! do |object|
14
+ parameters.map do |param|
15
+ object.send(param).is_a?(String) ? I18n.transliterate(object.send(param)).downcase : object.send(param)
16
+ end
17
+ end
18
+
19
+ # Any rejected (nil) values will be added to the start of the result unless specified otherwise
20
+ args[:prepend_rejected] ? rejected.concat(list) : list.concat(rejected)
21
+ end
22
+
23
+ def self.reverse_sort_by(args)
24
+ Parliament::Utils.sort_by(args).reverse!
25
+ end
26
+
27
+ private_class_method
28
+
29
+ def self.sort_defaults
30
+ {
31
+ prepend_rejected: true
32
+ }
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Parliament
2
- VERSION = '0.5.17'.freeze
2
+ VERSION = '0.5.18'.freeze
3
3
  end
data/lib/parliament.rb CHANGED
@@ -4,6 +4,7 @@ require 'grom'
4
4
  require 'parliament/version'
5
5
  require 'parliament/request'
6
6
  require 'parliament/response'
7
+ require 'parliament/utils'
7
8
  require 'parliament/no_content_error'
8
9
 
9
10
  # require all the decorators
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.17
4
+ version: 0.5.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Rayner
@@ -138,8 +138,8 @@ files:
138
138
  - CODE_OF_CONDUCT.md
139
139
  - Gemfile
140
140
  - LICENSE
141
- - Makefile
142
141
  - README.md
142
+ - Rakefile
143
143
  - bin/console
144
144
  - bin/setup
145
145
  - lib/parliament.rb
@@ -160,6 +160,7 @@ files:
160
160
  - lib/parliament/no_content_error.rb
161
161
  - lib/parliament/request.rb
162
162
  - lib/parliament/response.rb
163
+ - lib/parliament/utils.rb
163
164
  - lib/parliament/version.rb
164
165
  - parliament-ruby.gemspec
165
166
  homepage: http://github.com/ukparliament/parliament_ruby
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.5.1
186
+ rubygems_version: 2.6.6
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Internal parliamentary data API wrapper for ruby
data/Makefile DELETED
@@ -1,15 +0,0 @@
1
-
2
- test:
3
- bundle exec rspec spec
4
-
5
- build:
6
- gem build parliament-ruby.gemspec
7
-
8
- deploy:
9
- gem push parliament-ruby-*.gem
10
-
11
- clean:
12
- rm parliament-ruby-*.gem
13
-
14
- release: build deploy clean
15
-