Class: Swarm::ExpressionEvaluator
- Inherits:
-
Object
- Object
- Swarm::ExpressionEvaluator
- Extended by:
- Forwardable
- Defined in:
- lib/swarm/evaluation/expression_evaluator.rb
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Instance Method Summary collapse
- #all_conditions_met? ⇒ Boolean
- #check_condition(type, exp) ⇒ Object
- #conditions ⇒ Object
- #eval(string) ⇒ Object
-
#initialize(expression) ⇒ ExpressionEvaluator
constructor
A new instance of ExpressionEvaluator.
- #workitem_context ⇒ Object
Constructor Details
#initialize(expression) ⇒ ExpressionEvaluator
Returns a new instance of ExpressionEvaluator.
10 11 12 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 10 def initialize(expression) @expression = expression end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
7 8 9 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 7 def expression @expression end |
Instance Method Details
#all_conditions_met? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 22 def all_conditions_met? conditions.all? { |type, exp| check_condition(type, exp) } end |
#check_condition(type, exp) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 28 def check_condition(type, exp) unless ["if", "unless"].include?(type) raise ArgumentError.new("Not a conditional") end result = eval(exp) type == "if" ? result : !result end |
#conditions ⇒ Object
36 37 38 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 36 def conditions Swarm::Support.slice(arguments, "if", "unless") end |
#eval(string) ⇒ Object
18 19 20 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 18 def eval(string) workitem_context.instance_eval(string) end |
#workitem_context ⇒ Object
14 15 16 |
# File 'lib/swarm/evaluation/expression_evaluator.rb', line 14 def workitem_context @workitem_context ||= WorkitemContext.new(workitem) end |