sorted 2.0.2 → 2.0.3

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: 17571af478bc9338550f0550dfe618c02bebfed7
4
- data.tar.gz: 5000ea79f79cdba6f8633c767f212492b5813c4a
3
+ metadata.gz: 47e5b8db73e27b5130e62753c00ec308e6c6886d
4
+ data.tar.gz: 4c8abeb0e9399f5d2558d202597199ed8d236bea
5
5
  SHA512:
6
- metadata.gz: b17a5cc1d3d5bb9a56805f67cf5a67b90ad16bcc3c6dd08f5bf4986f70702bd5a3b3965dc77fd868dc619a58aa6f40abdc61eeb1b0028dfbd83aa07e58181b4b
7
- data.tar.gz: b86b3af64d2cae38b0a3349b024d4611230cdea89f1d589995c0dcaab6374c1b19c2822ac743bf8b5f556d168b32b52264495ddfa8c378d9019572ed05c0918e
6
+ metadata.gz: a1974de003bae9e48872f9652f209c5c374c0432d29635f1e169ef52ff3a0e626adff2bd2a8fa23ae583fe49cb98534e834ba82f36b1c285c456179f614ecb93
7
+ data.tar.gz: f9d8cba70836197f131ce03c3c36c35318284842d8a40aeb2ae3b4815d411c8e142949900257541b986be0c47f6ff97a06d3c0d5de7709aff3630ad15464f394
data/README.md CHANGED
@@ -35,6 +35,7 @@ Currently implemented:
35
35
  * `Sorted::SQLQuery`
36
36
  * `Sorted::URIQuery`
37
37
  * `Sorted::JSONQuery`
38
+ * `Sorted::ElasticsearchQuery`
38
39
  * `Sorted::ParamsQuery`
39
40
 
40
41
  ## Projects
@@ -212,6 +212,32 @@ module Sorted
212
212
  end
213
213
  end
214
214
 
215
+ ##
216
+ # Parses an Elasticsearch type set of order
217
+ #
218
+ # Parsing:
219
+ #
220
+ # params = [{ 'email' => {'order' => 'desc'}}]
221
+ # set = Sorted::ElasticsearchQuery.parse(params)
222
+ # set.to_a #=> [['email', 'desc']]
223
+ #
224
+ # Encoding:
225
+ #
226
+ # Sorted::ParamsQuery.encode(set) #=> [{ 'email' => {'order' => 'desc'}}]
227
+ #
228
+
229
+ class ElasticsearchQuery
230
+ extend Parse
231
+
232
+ def self.parse(raw)
233
+ Set.new(raw.each_with_object([]) { |hash, a| a << [hash.first.first, hash.first.last['order']] })
234
+ end
235
+
236
+ def self.encode(set)
237
+ set.to_a.each_with_object([]) { |f, a| a << { f.first => { 'order' => f.last } } }
238
+ end
239
+ end
240
+
215
241
  ##
216
242
  # Parses an array of decoded query params
217
243
  #
@@ -1,3 +1,3 @@
1
1
  module Sorted
2
- VERSION = '2.0.2'
2
+ VERSION = '2.0.3'
3
3
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sorted::ElasticsearchQuery, 'decode' do
4
+ it 'should decode elasticsearch order hash to into set' do
5
+ json = [{ 'email' => { 'order' => 'desc' } }, { 'phone' => { 'order' => 'asc' } }, { 'name' => { 'order' => 'desc' } }]
6
+ set = Sorted::ElasticsearchQuery.parse(json)
7
+ result = Sorted::Set.new([['email', 'desc'], ['phone', 'asc'], ['name', 'desc']])
8
+
9
+ expect(set).to eq(result)
10
+ end
11
+ end
12
+
13
+ describe Sorted::ElasticsearchQuery, 'encode' do
14
+ it 'should encode set into elasticsearch order hash' do
15
+ set = Sorted::Set.new([['email', 'desc'], ['phone', 'asc'], ['name', 'desc']])
16
+ result = [{ 'email' => { 'order' => 'desc' } }, { 'phone' => { 'order' => 'asc' } }, { 'name' => { 'order' => 'desc' } }]
17
+
18
+ expect(Sorted::ElasticsearchQuery.encode(set)).to eq(result)
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorted
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rufus Post
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -85,6 +85,7 @@ files:
85
85
  - lib/sorted.rb
86
86
  - lib/sorted/version.rb
87
87
  - sorted.gemspec
88
+ - spec/elasticsearch_query_spec.rb
88
89
  - spec/json_query_spec.rb
89
90
  - spec/params_query_spec.rb
90
91
  - spec/set_spec.rb