msfl 0.0.1.pre.rc8 → 1.0.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: f158def0dd3c1a90afd52ac221d85b95e68f940b
4
- data.tar.gz: 218ac6a18e360fb3710f6528739001ab2454305f
3
+ metadata.gz: 563d3ef0c03cf0f730fce20bca483a0821114b07
4
+ data.tar.gz: 55d9c65bd08ff2112be042f643cb5db0e02ffbc0
5
5
  SHA512:
6
- metadata.gz: e1a4bdaec608a350ca1aa02861ab1978c8f534fa6a54575740e9bd898f2070271902835eef85454025df7e0139ad4ad0307ab65ee2c791ca2a988ed177debfc8
7
- data.tar.gz: 4e6b90ab7c4dc28cdee6eb83dc106b18958e1df6a123e18cf8342b826b48ab2a9d342430b0cb7494083bb6684aa1f81df99589850e26dd215095f6c4ce28f142
6
+ metadata.gz: d9c693af109604a14129e16660d56ef5430b7039a4ada968a1d66c78cdf5be537154d7d7fcd87b577d626619ce81260aa715fa19a790d8a1636f4827946d0d25
7
+ data.tar.gz: ca8a5143b80148cd2f37527c87400ce72abb527833299645af6ed592c9d861a73167f3adb094f19b8780bb05fddb280622d74218a2bf3869b21aa90aff39d2d2
@@ -13,6 +13,7 @@ module MSFL
13
13
  obj = ::JSON.parse(json_to_parse)
14
14
  obj = arrays_to_sets obj
15
15
  obj = convert_keys_to_symbols obj
16
+ obj = convert_between_to_gte_lte obj
16
17
  obj
17
18
  end
18
19
 
@@ -56,6 +57,34 @@ module MSFL
56
57
  end
57
58
  result
58
59
  end
60
+
61
+ # Recursively converts all between operators to equivalent anded gte / lte
62
+ # it currently creates the converted operators in the implied AND format
63
+ #
64
+ # @param obj [Object] the object to recurse through to convert all betweens to gte / ltes
65
+ # @return [Object] the object with betweens converted to anded gte / ltes
66
+ def self.convert_between_to_gte_lte(obj)
67
+ result = obj
68
+ if obj.is_a? Hash
69
+ obj.each do |k, v|
70
+ if v.is_a?(Hash) && v.has_key?(:between) && v[:between].has_key?(:start) && v[:between].has_key?(:end)
71
+ lower_bound = convert_between_to_gte_lte v[:between][:start]
72
+ upper_bound = convert_between_to_gte_lte v[:between][:end]
73
+ result[k] = { gte: lower_bound, lte: upper_bound }
74
+ else
75
+ result[k] = convert_between_to_gte_lte v
76
+ end
77
+ end
78
+ elsif obj.is_a? Types::Set
79
+ result = Types::Set.new
80
+ obj.each do |v|
81
+ result << convert_between_to_gte_lte(v)
82
+ end
83
+ elsif obj.is_a? Array
84
+ raise ArgumentError, ".convert_between_to_gte_lte requires its argument to have been preprocessed by .arrays_to_sets and .convert_keys_to_symbols"
85
+ end
86
+ result
87
+ end
59
88
  end
60
89
  end
61
90
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'msfl'
3
- s.version = '0.0.1-rc8'
4
- s.date = '2015-03-26'
3
+ s.version = '1.0.0'
4
+ s.date = '2015-04-01'
5
5
  s.summary = "MSFL in Ruby"
6
6
  s.description = "Serializers, validators, and other tasty goodness for the Mattermark Semantic Filter Language in Ruby."
7
7
  s.authors = ["Courtland Caldwell"]
@@ -36,6 +36,129 @@ describe "MSFL::Parsers::JSON" do
36
36
 
37
37
  end
38
38
 
39
+ describe ".convert_between_to_gte_lte" do
40
+
41
+ subject(:mut) { MSFL::Parsers::JSON.convert_between_to_gte_lte arg }
42
+
43
+ let(:arg) { Object.new }
44
+
45
+ let(:deep_nest) do
46
+ {
47
+ cat: 1221,
48
+ dog: "fur",
49
+ lol: MSFL::Types::Set.new([ { hat: { between: { start: 1, end: 5 } } } ]),
50
+ :"1337" => 1337.1337, noob: MSFL::Types::Set.new([ MSFL::Types::Set.new([123]), { :"123" => 456, onetwo: 34 } ]) }
51
+ end
52
+
53
+ context "when the argument is a type other than MSFL::Types::Set, Hash, or Array" do
54
+
55
+ [55, 60.9, "five", :fourty, nil].each do |item|
56
+ context "when the argument is a #{item.class}" do
57
+
58
+ let(:arg) { item }
59
+
60
+ it "is equal to the argument" do
61
+ expect(mut).to eq arg
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ context "when the argument is a Hash" do
68
+
69
+ let(:arg) { { foo: { between: { start: "2015-01-01", end: "2015-04-01" } } } }
70
+
71
+ let(:expected) { { foo: { gte: "2015-01-01", lte: "2015-04-01" } } }
72
+
73
+ it "converts between clauses into anded gte / lte clauses" do
74
+ expect(mut).to eq expected
75
+ end
76
+
77
+ context "when the between clause is below the second level" do
78
+
79
+ let(:arg) do
80
+ {
81
+ and: MSFL::Types::Set.new([
82
+ { foo: { between: { start: -500, end: 12 } } },
83
+ { bar: { dog: "cat" } },
84
+ ])
85
+ }
86
+ end
87
+
88
+ let(:expected) do
89
+ {
90
+ and: MSFL::Types::Set.new([
91
+ { foo: { gte: -500, lte: 12 } },
92
+ { bar: { dog: "cat" } }
93
+ ])
94
+ }
95
+ end
96
+
97
+ it "recursively converts between clauses into anded gte / lte clauses" do
98
+ expect(mut).to eq expected
99
+ end
100
+ end
101
+ end
102
+
103
+ context "when the argument is a MSFL::Types::Set" do
104
+
105
+ let(:arg) { MSFL::Types::Set.new([ { foo: { between: { start: 1, end: 5 } } } ])}
106
+
107
+ let(:expected) { MSFL::Types::Set.new([ { foo: { gte: 1, lte: 5 } } ]) }
108
+
109
+ it "recursively converts between clauses into anded gte / lte clauses" do
110
+ expect(mut).to eq expected
111
+ end
112
+
113
+ context "when the between clause is below the second level" do
114
+
115
+ let(:arg) { MSFL::Types::Set.new([ { and: MSFL::Types::Set.new([{foo: { between: { start: 1, end: 5 } } }, {bar: 123}]) } ])}
116
+
117
+ let(:expected) { MSFL::Types::Set.new([ { and: MSFL::Types::Set.new([{ foo: { gte: 1, lte: 5} }, { bar: 123} ]) }]) }
118
+
119
+ it "recursively converts between clauses into anded gte / lte clauses" do
120
+ expect(mut).to eq expected
121
+ end
122
+ end
123
+ end
124
+
125
+ context "when the argument contains an Array" do
126
+
127
+ let(:arg) { [ { foo: { between: { start: 1, end: 5 } } } ] }
128
+
129
+ it "raises an ArgumentError" do
130
+ expect { mut }.to raise_error ArgumentError
131
+ end
132
+ end
133
+
134
+ context "when the argument is deeply nested and contains many types" do
135
+
136
+ let(:arg) { MSFL::Types::Set.new([deep_nest]) }
137
+
138
+ let(:expected) do
139
+ MSFL::Types::Set.new([
140
+ {
141
+ cat: 1221,
142
+ dog: "fur",
143
+ lol: MSFL::Types::Set.new(
144
+ [
145
+ { hat: { gte: 1, lte: 5} }
146
+ ]),
147
+ :"1337" => 1337.1337,
148
+ noob: MSFL::Types::Set.new(
149
+ [
150
+ MSFL::Types::Set.new([123]),
151
+ { :"123" => 456, onetwo: 34 }
152
+ ])
153
+ }])
154
+ end
155
+
156
+ it "recursively converts between clauses into anded gte / lte clauses" do
157
+ expect(mut).to eq expected
158
+ end
159
+ end
160
+ end
161
+
39
162
  describe ".arrays_to_sets" do
40
163
 
41
164
  subject(:mut) { MSFL::Parsers::JSON.arrays_to_sets arg }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msfl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.rc8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Courtland Caldwell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -148,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - '>'
151
+ - - '>='
152
152
  - !ruby/object:Gem::Version
153
- version: 1.3.1
153
+ version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
156
  rubygems_version: 2.4.2