Class: Mongoid::Criterion::OuterOperator

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

Overview

{:outer_operator => ‘within’, :operator => ‘center’ } { :location => { “$within” => { “$center” => [ [ 50, -40 ], 1 ] } } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ OuterOperator

Create the new complex criterion.



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

def initialize(opts = {})
  @key = opts[:key]
  @operator = opts[:operator]
  @outer_op = opts[:outer_op]        
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

#operatorObject

Returns the value of attribute operator.



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

def operator
  @operator
end

#outer_opObject

Returns the value of attribute outer_op.



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

def outer_op
  @outer_op
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
# File 'lib/mongoid/geo/criterion/outer_operator.rb', line 39

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



31
32
33
# File 'lib/mongoid/geo/criterion/outer_operator.rb', line 31

def hash
  [@outer_op, [@operator, @key]].hash
end

#make_hash(v) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/mongoid/geo/criterion/outer_operator.rb', line 21

def make_hash v                               
  if operator =~ /box/
    v = extract_box(v) if !v.kind_of?(Array)
    v = [to_point(v.first), to_point(v.last)]
  end
  
  v = extract_circle(v) if !v.kind_of?(Array) && operator =~ /center/
  {"$#{outer_op}" => {"$#{operator}" => v } }
end