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 |
# 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 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
39 40 41 42 43 |
# File 'lib/motion_blender/analyzer/source.rb', line 39 def attributes %w(code file line type method).map do |k| [k, instance_variable_get("@#{k}")] end.to_h.as_json end |
#children ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/motion_blender/analyzer/source.rb', line 28 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
24 25 26 |
# File 'lib/motion_blender/analyzer/source.rb', line 24 def evaluated! @evaluated = true end |