Class: Predicator::Predicates::Relation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Relation

Returns a new instance of Relation.



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

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

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



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

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

Instance Method Details

#==(other) ⇒ Object



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

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

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

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/predicator/predicates/relation.rb', line 10

def satisfied? context=Predicator::Context.new
  lhs, rhs = values_for_comparison context
  compare_values lhs, rhs
rescue NilValueError
  return false
end

#values_for_comparison(context = Context.new) ⇒ Object



17
18
19
20
21
22
# File 'lib/predicator/predicates/relation.rb', line 17

def values_for_comparison context=Context.new
  left_node = context.node_for left
  right_node = context.node_for right
  method = "compare_to_#{left_node.type}"
  [left_node.value, right_node.send(method)]
end