Class: MotionBlender::Analyzer::Source
- Inherits:
-
Object
- Object
- MotionBlender::Analyzer::Source
- Defined in:
- lib/motion_blender/analyzer/source.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#evaluated ⇒ Object
(also: #evaluated?)
readonly
Returns the value of attribute evaluated.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #attributes ⇒ Object
- #children ⇒ Object
- #evaluated! ⇒ Object
-
#initialize(attrs = {}) ⇒ Source
constructor
A new instance of Source.
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
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def ast @ast end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def code @code end |
#evaluated ⇒ Object (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 |
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def line @line end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def method @method end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lib/motion_blender/analyzer/source.rb', line 4 def parent @parent end |
#type ⇒ Object (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
#attributes ⇒ Object
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 |
#children ⇒ Object
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 |