parliament-ntriple 0.4.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: 959375f5bbe02076050c514ba6e4f7def9aacbd3
4
- data.tar.gz: 682b57eac0049bd9a92a8d3aca7e4024393892a2
2
+ SHA256:
3
+ metadata.gz: 8bca56b0fd2e5d632150f373039d94c28902225e3fcc9394b0b6b8cab5184329
4
+ data.tar.gz: c05ec7fe015bc0eba75973167b870ea2425fdaef96d4bc60aeda72fd06c9194c
5
5
  SHA512:
6
- metadata.gz: ceb92a6eba55fda689d0cef11988833563220aa6ba9eb3db6f183245b88a5fe0ab7b2641c5070428fe2ab85146e8e91c3eaf313b088bf0b282b6c88a991de1fb
7
- data.tar.gz: 23796e4da1efbe568b5f0d2c9bb40f0ba312f0d10ddbceecea652f4686fdcbaf31ba45cb7450f03d9ac874879a49358d26b2c1fb936979299a8ab477e615aabf
6
+ metadata.gz: d9ffb8c15378f94485bf2ba9dc16a7d987731d6edff3edb463f4414736d780ad97666dfe4512434e5ec448889e98c01ddc392c17863bf7c8357aaf91c8ed2691
7
+ data.tar.gz: 1d9e477300e2575ce4e2b4622af3923c35445c5e6eb5d147e3a6b5f360f048b5325e2ab5a7df70f55db9033a80e7b1003976943005d1285b13c44230285f47fb
@@ -32,6 +32,7 @@ module Parliament
32
32
  # @param [Hash] args a hash of arguments.
33
33
  # @option args [Array<Object>] :list the 'list' which we are sorting.
34
34
  # @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
35
+ # @option args [Proc] :block a block used to sort.
35
36
  # @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
36
37
  #
37
38
  # @return [Array<Object>] a sorted array of objects using the args passed in.
@@ -40,10 +41,11 @@ module Parliament
40
41
  args = sort_defaults.merge(args)
41
42
  list = args[:list].dup
42
43
  parameters = args[:parameters]
44
+ block = args[:block]
43
45
 
44
- list, rejected = prune_list(list, rejected, parameters)
46
+ list, rejected = prune_list(list, rejected, parameters, block)
45
47
 
46
- list = sort_list(list, parameters)
48
+ list = sort_list(list, parameters, block)
47
49
 
48
50
  # Any rejected (nil) values will be added to the start of the result unless specified otherwise
49
51
  args[:prepend_rejected] ? rejected.concat(list) : list.concat(rejected)
@@ -77,6 +79,7 @@ module Parliament
77
79
  # @param [Hash] args a hash of arguments.
78
80
  # @option args [Array<Object>] :list the 'list' which we are sorting.
79
81
  # @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
82
+ # @option args [Proc] :block a block used to sort.
80
83
  # @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
81
84
  #
82
85
  # @return [Array<Object>] a sorted array of objects using the args passed in.
@@ -126,7 +129,7 @@ module Parliament
126
129
  list = args[:list].dup
127
130
  sort_directions = args[:parameters]
128
131
 
129
- list, rejected = prune_list(list, rejected, sort_directions.keys)
132
+ list, rejected = prune_list(list, rejected, sort_directions.keys, nil)
130
133
 
131
134
  list = multi_sort_list(list, sort_directions)
132
135
 
@@ -144,13 +147,24 @@ module Parliament
144
147
  # @param [Array<Object>] list the 'list' of objects we are pruning from.
145
148
  # @param [Array<Object>] rejected the objects we have pruned from list.
146
149
  # @param [Array<Symbol>] parameters an array of parameters we are checking.
150
+ # @param [Proc] block a block used to cjecl
147
151
  #
148
152
  # @return [Array<Array<Object>, Array<Object>>] an array containing first, the pruned list and secondly, the rejected list.
149
- private_class_method def self.prune_list(list, rejected, parameters)
150
- list.delete_if do |object|
151
- rejected << object unless parameters.all? { |param| !object.send(param).nil? if object.respond_to?(param) }
153
+ private_class_method def self.prune_list(list, rejected, parameters, block)
154
+ if parameters
155
+ rejection_block = proc do |object|
156
+ rejected << object unless parameters.all? { |param| !object.send(param).nil? if object.respond_to?(param) }
157
+ end
158
+ end
159
+
160
+ if block
161
+ rejection_block = proc do |object|
162
+ rejected << object if block.call(object).nil?
163
+ end
152
164
  end
153
165
 
166
+ list.delete_if { |object| rejection_block.call(object) } if rejection_block
167
+
154
168
  [list, rejected]
155
169
  end
156
170
 
@@ -163,14 +177,23 @@ module Parliament
163
177
  #
164
178
  # @param [Array<Object>] list the 'list' of objects we are pruning from.
165
179
  # @param [Array<Symbol>] parameters a hash of parameters to sort by as keys and the sort direction as values.
180
+ # @param [Proc] block a block used to sort.
166
181
  #
167
182
  # @return [Array<Object>] our sorted list.
168
- private_class_method def self.sort_list(list, parameters)
169
- list.sort_by! do |object|
170
- parameters.map do |param|
171
- object.send(param).is_a?(String) ? I18n.transliterate(object.send(param)).downcase : object.send(param)
183
+ private_class_method def self.sort_list(list, parameters, block)
184
+ if parameters
185
+ sort_block = proc do |object|
186
+ parameters.map do |param|
187
+ object.send(param).is_a?(String) ? I18n.transliterate(object.send(param)).downcase : object.send(param)
188
+ end
172
189
  end
173
190
  end
191
+
192
+ sort_block = block if block
193
+
194
+ return list if sort_block.nil?
195
+
196
+ list.sort_by! { |object| sort_block.call(object) }
174
197
  end
175
198
 
176
199
  # @!method self.multi_sort_list(list, sort_directions)
@@ -1,5 +1,5 @@
1
1
  module Parliament
2
2
  module NTriple
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-ntriple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rebecca Appleyard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grom
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  requirements: []
199
199
  rubyforge_project:
200
- rubygems_version: 2.6.8
200
+ rubygems_version: 2.7.6
201
201
  signing_key:
202
202
  specification_version: 4
203
203
  summary: Parliamentary NTriple response builder