Class: Mongoid::Criterion::TwinOperators

Inherits:
Object
  • Object
show all
Includes:
Geo::PointConversion
Defined in:
lib/mongoid/geo/criterion/twin_operators.rb

Overview

{:opA => ‘near’, :opB => ‘maxDistance’ } :location => { $near => [50,50], $maxDistance => 5 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TwinOperators

Create the new complex criterion.



15
16
17
18
19
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 15

def initialize(opts = {})
  @key = opts[:key]
  @op_a = opts[:op_a]
  @op_b = opts[:op_b]        
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 12

def key
  @key
end

#op_aObject

Returns the value of attribute op_a.



12
13
14
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 12

def op_a
  @op_a
end

#op_bObject

Returns the value of attribute op_b.



12
13
14
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 12

def op_b
  @op_b
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 34

def ==(other)
  return false unless other.is_a?(self.class)        
  self.op_a == other.op_a && self.op_b == other.op_b && self.key == other.key 
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 30

def eql?(other)
  self == (other)
end

#hashObject



26
27
28
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 26

def hash
  [@op_a, @op_b, @key].hash
end

#make_hash(v) ⇒ Object



21
22
23
24
# File 'lib/mongoid/geo/criterion/twin_operators.rb', line 21

def make_hash v     
  v = extract_nearMax(v) if !v.kind_of?(Array) && op_b =~ /max/i
  {"$#{op_a}" => to_point(v.first), "$#{op_b}" => to_point(v.last) }
end