msfl 1.2.0.dev4 → 1.2.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 +4 -4
- data/README.md +44 -0
- data/lib/msfl/converters/operator.rb +3 -0
- data/lib/msfl/validators/definitions/hash_key.rb +10 -1
- data/msfl.gemspec +1 -1
- data/spec/msfl/converters/operator_spec.rb +14 -1
- data/spec/msfl/datasets/base_spec.rb +9 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ef0585bfa75b7826d47d868b90dfbf41db7974
|
4
|
+
data.tar.gz: efa739290d0c5d8385bcf6c058505d61a3655d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414df49e29c8205a0e9aa0f1f2cf2d50e7876c730ddbdb2b47e865f42fd7f4734aa5b90002edda0c8dea1a03f4b6d075f4677d36538a168533e976bf19fa49f9
|
7
|
+
data.tar.gz: 164c713872e391bf2a94a373a852b01ab6b0cea05a41698ea9cec4cf11aebf056dd0f512afe914c31464bb24892e8855898203baa936b2b16827e0a08e281461
|
data/README.md
CHANGED
@@ -17,6 +17,50 @@ that you need faceted filtering in your application then this will seem second n
|
|
17
17
|
|
18
18
|
Contains serializers and validators (and perhaps other) MSFL goodies
|
19
19
|
|
20
|
+
# Converters
|
21
|
+
|
22
|
+
One aspect of the msfl gem is the conversion of standard msfl into what we internally call NMSFL (normalized Mattermark
|
23
|
+
Semantic Filter Language). NMSFL serves as an intermediate language in which some of the human friendly conveniences
|
24
|
+
are replaced with a syntax that is easier for machines to parse.
|
25
|
+
|
26
|
+
## A noop conversion
|
27
|
+
```ruby
|
28
|
+
require 'msfl'
|
29
|
+
# Require one of the test datasets
|
30
|
+
require 'msfl/datasets/car'
|
31
|
+
|
32
|
+
msfl = { make: "Chevy" }
|
33
|
+
converter = MSFL::Converters::Operator.new
|
34
|
+
nmsfl = converter.run_conversions msfl
|
35
|
+
|
36
|
+
=> {:make=>"Chevy"}
|
37
|
+
```
|
38
|
+
|
39
|
+
## A conversion from an implicit AND to an explicit one
|
40
|
+
```ruby
|
41
|
+
require 'msfl'
|
42
|
+
# Require one of the test datasets
|
43
|
+
require 'msfl/datasets/car'
|
44
|
+
|
45
|
+
msfl = { make: "Chevy", year: { gt: 2000 } }
|
46
|
+
converter = MSFL::Converters::Operator.new
|
47
|
+
nmsfl = converter.run_conversions msfl
|
48
|
+
|
49
|
+
=> {:and=>#<MSFL::Types::Set: {{:make=>"Chevy"}, {:year=>{:gt=>2000}}}>}
|
50
|
+
```
|
51
|
+
|
52
|
+
## A conversion from between to gte / lte
|
53
|
+
```ruby
|
54
|
+
require 'msfl'
|
55
|
+
# Require one of the test datasets
|
56
|
+
require 'msfl/datasets/car'
|
57
|
+
|
58
|
+
msfl = { year: { between: { start: 2010, end: 2015 } } }
|
59
|
+
converter = MSFL::Converters::Operator.new
|
60
|
+
nmsfl = converter.run_conversions msfl
|
61
|
+
|
62
|
+
=> {:and=>#<MSFL::Types::Set: {{:year=>{:gte=>2010}}, {:year=>{:lte=>2015}}}>}
|
63
|
+
```
|
20
64
|
## EBNF
|
21
65
|
|
22
66
|
MSFL is a context-free language. The context-free grammar is defined below.
|
@@ -109,6 +109,9 @@ module MSFL
|
|
109
109
|
result = i_to_e_bin_op obj, parent_key
|
110
110
|
elsif logical_operators.include?(first_key)
|
111
111
|
result = i_to_e_log_op obj, parent_key
|
112
|
+
elsif first_key == :partial
|
113
|
+
result = { partial: { given: implicit_and_to_explicit_recursively(obj[:partial][:given]),
|
114
|
+
filter: implicit_and_to_explicit_recursively(obj[:partial][:filter]) } }
|
112
115
|
else
|
113
116
|
# the first key is not an operator
|
114
117
|
# if there is only one key just assign the result of calling this method recursively on the value to the result for the key
|
@@ -13,7 +13,7 @@ module MSFL
|
|
13
13
|
|
14
14
|
# Operators still needing parsing: ellipsis2, tilda
|
15
15
|
def hash_key_operators
|
16
|
-
binary_operators.concat(logical_operators)
|
16
|
+
binary_operators.concat(logical_operators).concat(partial_operators)
|
17
17
|
end
|
18
18
|
|
19
19
|
def binary_operators
|
@@ -30,6 +30,15 @@ module MSFL
|
|
30
30
|
:gt, # >
|
31
31
|
:gte, # >=
|
32
32
|
:neg, # logical negation
|
33
|
+
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
def partial_operators
|
38
|
+
[
|
39
|
+
:partial, # faceted / aggregate
|
40
|
+
:given, # given
|
41
|
+
:filter, # explicit filter
|
33
42
|
]
|
34
43
|
end
|
35
44
|
|
data/msfl.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'msfl'
|
3
|
-
s.version = '1.2.0
|
3
|
+
s.version = '1.2.0'
|
4
4
|
s.date = '2015-05-12'
|
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."
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe MSFL::Converters::Operator do
|
4
4
|
|
5
5
|
describe "#run_conversions" do
|
6
6
|
|
@@ -573,4 +573,17 @@ describe "MSFL::Converters::Operator" do
|
|
573
573
|
end
|
574
574
|
end
|
575
575
|
end
|
576
|
+
|
577
|
+
describe "running conversions on a normal msfl filter containing a partial" do
|
578
|
+
|
579
|
+
subject { converter.run_conversions msfl }
|
580
|
+
|
581
|
+
let(:converter) { described_class.new }
|
582
|
+
|
583
|
+
let(:msfl) { { partial: { given: { make: "Toyota" }, filter: { avg_age: 10 } } } }
|
584
|
+
|
585
|
+
it "is unchanged" do
|
586
|
+
expect(subject).to eq msfl
|
587
|
+
end
|
588
|
+
end
|
576
589
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msfl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
@@ -152,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- - "
|
155
|
+
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
157
|
+
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
160
|
rubygems_version: 2.2.2
|