Class: Imagen::Node::Base
- Inherits:
-
Object
- Object
- Imagen::Node::Base
show all
- Defined in:
- lib/imagen/node.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
14
15
16
|
# File 'lib/imagen/node.rb', line 14
def initialize
@children = []
end
|
Instance Attribute Details
#ast_node ⇒ Object
Returns the value of attribute ast_node.
10
11
12
|
# File 'lib/imagen/node.rb', line 10
def ast_node
@ast_node
end
|
#children ⇒ Object
Returns the value of attribute children.
10
11
12
|
# File 'lib/imagen/node.rb', line 10
def children
@children
end
|
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/imagen/node.rb', line 10
def name
@name
end
|
Instance Method Details
#build_from_ast(ast_node) ⇒ Object
22
23
24
|
# File 'lib/imagen/node.rb', line 22
def build_from_ast(ast_node)
tap { @ast_node = ast_node }
end
|
#file_path ⇒ Object
26
27
28
|
# File 'lib/imagen/node.rb', line 26
def file_path
ast_node.location.name.source_buffer.name
end
|
#find_all(matcher, ret = []) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/imagen/node.rb', line 57
def find_all(matcher, ret = [])
ret.tap do
ret << self if matcher.call(self)
children.each { |child| child.find_all(matcher, ret) }
end
end
|
#first_line ⇒ Object
30
31
32
|
# File 'lib/imagen/node.rb', line 30
def first_line
ast_node.location.first_line
end
|
#human_name ⇒ Object
18
19
20
|
# File 'lib/imagen/node.rb', line 18
def human_name
raise NotImplementedError
end
|
#last_line ⇒ Object
38
39
40
|
# File 'lib/imagen/node.rb', line 38
def last_line
ast_node.location.last_line
end
|
#line_numbers ⇒ Object
34
35
36
|
# File 'lib/imagen/node.rb', line 34
def line_numbers
(first_line..last_line).to_a
end
|
#source ⇒ Object
42
43
44
|
# File 'lib/imagen/node.rb', line 42
def source
source_lines.join("\n")
end
|
#source_lines ⇒ Object
50
51
52
53
54
55
|
# File 'lib/imagen/node.rb', line 50
def source_lines
ast_node.location.expression.source_buffer.source_lines[
first_line - 1,
last_line
]
end
|
#source_lines_with_numbers ⇒ Object
46
47
48
|
# File 'lib/imagen/node.rb', line 46
def source_lines_with_numbers
(first_line..last_line).zip(source_lines)
end
|