Class: Factbase::Term
- Inherits:
-
Object
- Object
- Factbase::Term
- Defined in:
- lib/factbase/term.rb
Overview
Term.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Attribute Summary collapse
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#operands ⇒ Object
readonly
Returns the value of attribute operands.
Instance Method Summary collapse
-
#initialize(operator, operands) ⇒ Term
constructor
Ctor.
-
#matches?(fact) ⇒ bool
Does it match the fact?.
-
#to_s ⇒ String
Turns it into a string.
Constructor Details
#initialize(operator, operands) ⇒ Term
Ctor.
36 37 38 39 |
# File 'lib/factbase/term.rb', line 36 def initialize(operator, operands) @op = operator @operands = operands end |
Instance Attribute Details
#op ⇒ Object (readonly)
Returns the value of attribute op.
31 32 33 |
# File 'lib/factbase/term.rb', line 31 def op @op end |
#operands ⇒ Object (readonly)
Returns the value of attribute operands.
31 32 33 |
# File 'lib/factbase/term.rb', line 31 def operands @operands end |
Instance Method Details
#matches?(fact) ⇒ bool
Does it match the fact?
44 45 46 |
# File 'lib/factbase/term.rb', line 44 def matches?(fact) send(@op, fact) end |
#to_s ⇒ String
Turns it into a string.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/factbase/term.rb', line 50 def to_s items = [] items << @op items += @operands.map do |o| if o.is_a?(String) "'#{o.gsub("'", "\\\\'").gsub('"', '\\\\"')}'" elsif o.is_a?(Time) o.utc.iso8601 else o.to_s end end "(#{items.join(' ')})" end |