hash_conditions 0.1.6 → 0.1.7

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.
@@ -95,23 +95,30 @@ module HashConditions
95
95
 
96
96
  def get_condition_from_expression expression
97
97
  {}.tap do | condition |
98
- condition[ expression[:operator] ] = expression[:value]
98
+ condition[ rev_op( expression[:operator] ) ] = expression[:value]
99
99
  end
100
100
  end
101
101
 
102
+ def ops
103
+ {
104
+ :== => [ '$eq', '$equal' ],
105
+ :!= => [ '$ne' ],
106
+ :> => [ '$gt' ],
107
+ :< => [ '$lt' ],
108
+ :>= => [ '$gte' ],
109
+ :<= => [ '$lte' ],
110
+ :between => [ '$between' ],
111
+ :in => [ "$in" ],
112
+ :contains => [ "$contains" ]
113
+ }
114
+ end
115
+
116
+ def rev_op key
117
+ ops[ key ] && ops[ key ].first or key
118
+ end
102
119
  def get_op key
103
- case key
104
- when '$eq', '$equal' then :==
105
- when '$ne', '$not_equal' then :!=
106
- when '$gt' then :>
107
- when '$lt' then :<
108
- when '$gte' then :>=
109
- when '$lte' then :<=
110
- when '$between' then :between
111
- when '$in' then :in
112
- when '$contains' then :contains
113
- else key
114
- end
120
+ pair = ops.find{ |k, v| Array(v).include? key }
121
+ pair && pair.first or key
115
122
  end
116
123
 
117
124
  def re_type data
@@ -1,3 +1,3 @@
1
1
  module HashConditions
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-02 00:00:00.000000000 Z
12
+ date: 2015-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: -1251210645115907226
105
+ hash: -4547086338447757306
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: -1251210645115907226
114
+ hash: -4547086338447757306
115
115
  requirements: []
116
116
  rubyforge_project:
117
117
  rubygems_version: 1.8.23