msfl 1.2.0.dev4 → 1.2.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
2
  SHA1:
3
- metadata.gz: 64f2f1391e2c2d84010f3f24dea6c05876914c0a
4
- data.tar.gz: 043011b2811609dca0d3c64f77bf3bc38fc18736
3
+ metadata.gz: b9ef0585bfa75b7826d47d868b90dfbf41db7974
4
+ data.tar.gz: efa739290d0c5d8385bcf6c058505d61a3655d42
5
5
  SHA512:
6
- metadata.gz: a76a648c5915c1f12bffe6df8ccbc177a664414046df5690d5e1ed71325b825aa2914a8b9ebc836376818347ff8db797adb35a2bb694cdbf37147fbd39d84217
7
- data.tar.gz: 60ba3c0cf3aedf8dea480b7eb79072a49002ec27a22143f2dbda12e66e1825be7bf29ce2374fe90b707c54a8566c536ac733684bbb9e2698127fb7f45ac4a992
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'msfl'
3
- s.version = '1.2.0.dev4'
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 "MSFL::Converters::Operator" do
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
@@ -66,4 +66,13 @@ describe "MSFL::Datasets::Base" do
66
66
  expect(mut).to eq errors
67
67
  end
68
68
  end
69
+
70
+ describe "#foreigns" do
71
+
72
+ subject { test_instance.foreigns }
73
+
74
+ it "is intended to be overridden" do
75
+ expect(subject).to eq []
76
+ end
77
+ end
69
78
  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.dev4
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: 1.3.1
157
+ version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
160
  rubygems_version: 2.2.2