Class: Predicator::Predicates::Relation
- Inherits:
-
Object
- Object
- Predicator::Predicates::Relation
- Defined in:
- lib/predicator/predicates/relation.rb
Direct Known Subclasses
Equal, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, NotEqual
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(left, right) ⇒ Relation
constructor
A new instance of Relation.
- #satisfied?(context = Predicator::Context.new) ⇒ Boolean
- #values_for_comparison(context = Context.new) ⇒ Object
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
#left ⇒ Object (readonly)
Returns the value of attribute left.
4 5 6 |
# File 'lib/predicator/predicates/relation.rb', line 4 def left @left end |
#right ⇒ Object (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
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 |