Class: MotionBlender::Analyzer::Source

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Source

Returns a new instance of Source.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/motion_blender/analyzer/source.rb', line 8

def initialize attrs = {}
  @evaluated = false
  ast = attrs.delete :ast
  if ast
    @code = ast.loc.expression.try(:source)
    @file = ast.loc.expression.try(:source_buffer).try(:name)
    @line = ast.loc.expression.try(:line)
    @type = ast.type.to_s.inquiry
    @method = @type.send? ? ast.children[1] : nil
    @ast = ast
  end
  attrs.each do |k, v|
    instance_variable_set "@#{k}", v
  end
  @type = @type.to_s.inquiry
  @method = @method.try(:to_sym)
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



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

def ast
  @ast
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#evaluatedObject (readonly) Also known as: evaluated?

Returns the value of attribute evaluated.



5
6
7
# File 'lib/motion_blender/analyzer/source.rb', line 5

def evaluated
  @evaluated
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



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

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#attributesObject



41
42
43
44
45
46
47
48
49
# File 'lib/motion_blender/analyzer/source.rb', line 41

def attributes
  {
    'code' => @code,
    'file' => @file,
    'line' => @line,
    'type' => @type.to_s,
    'method' => @method.try(:to_s)
  }
end

#childrenObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/motion_blender/analyzer/source.rb', line 30

def children
  @children ||=
    if @ast
      @ast.children.grep(::Parser::AST::Node).map do |ast|
        Source.new(ast: ast, parent: self)
      end
    else
      []
    end
end

#evaluated!Object



26
27
28
# File 'lib/motion_blender/analyzer/source.rb', line 26

def evaluated!
  @evaluated = true
end