Class: Predicator::Predicates::Between

Inherits:
Object
  • Object
show all
Defined in:
lib/predicator/predicates/between.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, left, right) ⇒ Between



6
7
8
# File 'lib/predicator/predicates/between.rb', line 6

def initialize value, left, right
  @value, @left, @right = value, left, right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



4
5
6
# File 'lib/predicator/predicates/between.rb', line 4

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



4
5
6
# File 'lib/predicator/predicates/between.rb', line 4

def right
  @right
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/predicator/predicates/between.rb', line 4

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
28
# File 'lib/predicator/predicates/between.rb', line 23

def == other
  other.kind_of?(self.class) &&
    other.value == value &&
    other.left == left &&
    other.right == right
end

#satisfied?(context = Predicator::Context.new) ⇒ Boolean



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/predicator/predicates/between.rb', line 10

def satisfied? context=Predicator::Context.new
  value_node = context.node_for value
  left_node = context.node_for left
  right_node = context.node_for right
  method = "compare_to_#{value_node.type}"

  left_value = left_node.send method
  right_value = right_node.send method

  (value_node.value >= left_value) &&
    (value_node.value <= right_value)
end