Class: MotionBlender::Analyzer::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_blender/analyzer/evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#astObject (readonly)

Returns the value of attribute ast.



4
5
6
# File 'lib/motion_blender/analyzer/evaluator.rb', line 4

def ast
  @ast
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/motion_blender/analyzer/evaluator.rb', line 4

def file
  @file
end

#stackObject (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_extractorObject



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_argsObject



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