hash_conditions 0.1.5 → 0.1.6
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.
- data/lib/hash_conditions/core.rb +21 -12
- data/lib/hash_conditions/matcher.rb +1 -1
- data/lib/hash_conditions/version.rb +1 -1
- metadata +3 -3
data/lib/hash_conditions/core.rb
CHANGED
@@ -37,7 +37,7 @@ module HashConditions
|
|
37
37
|
when '$and' then iterator(value, options.merge( glue: :and ))
|
38
38
|
when '$or' then iterator(value, options.merge( glue: :or))
|
39
39
|
when '$eval' then results_from_expression( eval_expression( value ), options )
|
40
|
-
when _ext_match( value, options ) then _ext_parse( key, value, options )
|
40
|
+
when _ext_match( value, options ) then _ext_parse( extract_expression(key, value) , options )
|
41
41
|
else results_from_expression( extract_expression( key, value ), options )
|
42
42
|
end
|
43
43
|
end
|
@@ -88,7 +88,15 @@ module HashConditions
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
re_type result
|
91
|
+
result[:value] = re_type result[:value]
|
92
|
+
|
93
|
+
result
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_condition_from_expression expression
|
97
|
+
{}.tap do | condition |
|
98
|
+
condition[ expression[:operator] ] = expression[:value]
|
99
|
+
end
|
92
100
|
end
|
93
101
|
|
94
102
|
def get_op key
|
@@ -102,30 +110,31 @@ module HashConditions
|
|
102
110
|
when '$between' then :between
|
103
111
|
when '$in' then :in
|
104
112
|
when '$contains' then :contains
|
105
|
-
else
|
106
|
-
raise "No operator for '#{ op }"
|
113
|
+
else key
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
110
117
|
def re_type data
|
111
|
-
if data
|
112
|
-
|
113
|
-
when /\d{4}-\d{2}-\d{2}
|
114
|
-
else data
|
118
|
+
if data.is_a? String
|
119
|
+
case data
|
120
|
+
when /\d{4}-\d{2}-\d{2}[\sT]\d{2}:\d{2}:\d{2}(\.\d{3})?Z?/ then DateTime.parse( data ).to_time
|
121
|
+
else data
|
115
122
|
end
|
123
|
+
else
|
124
|
+
data
|
116
125
|
end
|
117
|
-
|
118
|
-
data
|
119
126
|
end
|
120
127
|
|
121
128
|
def _ext_match condition, options
|
122
129
|
->(key) { _ext_get_module( key, condition, options ) != nil }
|
123
130
|
end
|
124
131
|
|
125
|
-
def _ext_parse
|
132
|
+
def _ext_parse expression, options
|
133
|
+
key, op, value = expression.values_at :key, :operator, :value
|
134
|
+
condition = get_condition_from_expression expression
|
135
|
+
|
126
136
|
mod = _ext_get_module key,condition, options
|
127
137
|
parser = mod.replacement
|
128
|
-
op, value = condition.to_a.first
|
129
138
|
|
130
139
|
case parser
|
131
140
|
when String then options[:result].call(extract_expression( parser, condition ), options)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_conditions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
segments:
|
104
104
|
- 0
|
105
|
-
hash:
|
105
|
+
hash: -1251210645115907226
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: -1251210645115907226
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
117
|
rubygems_version: 1.8.23
|