Class: ReDuxml::Evaluator
- Inherits:
-
Object
- Object
- ReDuxml::Evaluator
- Defined in:
- lib/re_duxml/evaluate.rb
Constant Summary collapse
- LOGIC_FILE =
File.(File.dirname(__FILE__) + '/../../xml/logic.xml')
Instance Attribute Summary collapse
-
#param_hash ⇒ Object
readonly
Returns the value of attribute param_hash.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Attributes included from ReDuxml
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
#initialize(logic = nil) ⇒ Evaluator
Returns a new instance of Evaluator.
17 18 19 20 |
# File 'lib/re_duxml/evaluate.rb', line 17 def initialize(logic=nil) @parser = Parser.new(logic || LOGIC_FILE) @param_hash = {} end |
Instance Attribute Details
#param_hash ⇒ Object (readonly)
Returns the value of attribute param_hash.
15 16 17 |
# File 'lib/re_duxml/evaluate.rb', line 15 def param_hash @param_hash end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
15 16 17 |
# File 'lib/re_duxml/evaluate.rb', line 15 def parser @parser end |
Instance Method Details
#evaluate(_expr, _param_hash = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/re_duxml/evaluate.rb', line 26 def evaluate(_expr, _param_hash={}) _param_hash.each do |key, val| @param_hash[key.to_s] = _param_hash[key] end expr = resolve_params _expr return expr if expr.parameterized? return expr if Regexp.identifier.match(expr).to_s == expr return expr.to_i if expr.to_i.to_s == expr result = reduce parser.parse expr case when result.respond_to?(:imaginary), result.class == TrueClass, result.class == FalseClass then result when result.respond_to?(:name) then result.name when result.respond_to?(:to_sexp) then result.print(parser.logic) else result.to_s end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/re_duxml/evaluate.rb', line 22 def to_s "#<Evaluator: param_hash: '#{param_hash.to_s}' parser_logic: '#{parser}'>" end |