Class: ReDuxml::Evaluator
- Inherits:
-
Object
- Object
- ReDuxml::Evaluator
- Defined in:
- lib/re_dux/evaluate.rb
Constant Summary collapse
- COMPARATORS =
%w(
Instance Attribute Summary collapse
-
#param_hash ⇒ Object
readonly
Returns the value of attribute param_hash.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #evaluate(_expr, _param_hash = {}) ⇒ Object
-
#initialize(logic = nil) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #to_s ⇒ Object
Methods included from Symbolic
Methods included from AST
Methods included from ReDuxml
Constructor Details
Instance Attribute Details
#param_hash ⇒ Object (readonly)
Returns the value of attribute param_hash.
14 15 16 |
# File 'lib/re_dux/evaluate.rb', line 14 def param_hash @param_hash end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
14 15 16 |
# File 'lib/re_dux/evaluate.rb', line 14 def parser @parser end |
Instance Method Details
#evaluate(_expr, _param_hash = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/re_dux/evaluate.rb', line 25 def evaluate(_expr, _param_hash={}) @param_hash = _param_hash expr = resolve_params _expr result = reduce parser.parse expr case when result.respond_to?(:imaginary), result.class == TrueClass, result.class == FalseClass then result when result.respond_to?(:print) then result.print(parser.logic) else result.to_s end end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/re_dux/evaluate.rb', line 21 def to_s "#<Evaluator: param_hash: '#{param_hash.to_s}' parser_logic: '#{parser}'>" end |