Class: MotionBlender::Analyzer::Evaluator
- Inherits:
-
Object
- Object
- MotionBlender::Analyzer::Evaluator
- Defined in:
- lib/motion_blender/analyzer/evaluator.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #create_extractor ⇒ Object
-
#initialize(file, ast, stack = [], method = nil) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #parse_args ⇒ Object
Constructor Details
#initialize(file, ast, stack = [], method = nil) ⇒ Evaluator
Returns a new instance of Evaluator.
6 7 8 9 10 11 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 6 def initialize file, ast, stack = [], method = nil @file = file @ast = ast @stack = stack @method = method || @ast.children[1] end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
4 5 6 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 4 def ast @ast end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 4 def file @file end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
4 5 6 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 4 def stack @stack end |
Instance Method Details
#create_extractor ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 26 def create_extractor obj = Object.new obj.define_singleton_method @method do |arg| @args ||= [] @args << arg end obj end |
#parse_args ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/motion_blender/analyzer/evaluator.rb', line 13 def parse_args extractor = create_extractor extractor.instance_eval(@ast.loc.expression.source, @file) extractor.instance_eval { @args || [] } rescue if stack.any? Evaluator.new(@file, stack.last, stack[0..-2], @method).parse_args else exp = @ast.loc.expression.source raise LoadError, "failed to parse `#{exp}'" end end |