Class: RailsRouteChecker::Parsers::HamlParser::Tree::Node
- Inherits:
-
Object
- Object
- RailsRouteChecker::Parsers::HamlParser::Tree::Node
show all
- Includes:
- Enumerable
- Defined in:
- lib/rails-route-checker/parsers/haml_parser/tree/node.rb
Defined Under Namespace
Classes: Siblings
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(document, parse_node) ⇒ Node
Returns a new instance of Node.
13
14
15
16
17
18
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 13
def initialize(document, parse_node)
@line = parse_node.line
@document = document
@value = parse_node.value
@type = parse_node.type
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
10
11
12
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 10
def children
@children
end
|
#line ⇒ Object
Returns the value of attribute line.
11
12
13
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 11
def line
@line
end
|
#parent ⇒ Object
Returns the value of attribute parent.
10
11
12
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 10
def parent
@parent
end
|
#type ⇒ Object
Returns the value of attribute type.
11
12
13
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 11
def type
@type
end
|
Instance Method Details
#directives ⇒ Object
30
31
32
33
34
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 30
def directives
directives = []
directives << predecessor.directives if predecessor
directives.flatten
end
|
#each ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 20
def each
return to_enum(__callee__) unless block_given?
node = self
loop do
yield node
break unless (node = node.next_node)
end
end
|
#inspect ⇒ Object
49
50
51
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 49
def inspect
"#<#{self.class.name}>"
end
|
#line_numbers ⇒ Object
59
60
61
62
63
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 59
def line_numbers
return (line..line) unless @value && text
(line..line + lines.count)
end
|
#lines ⇒ Object
53
54
55
56
57
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 53
def lines
return [] unless @value && text
text.split(/\r\n|\r|\n/)
end
|
#next_node ⇒ Object
76
77
78
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 76
def next_node
children.first || successor
end
|
#predecessor ⇒ Object
65
66
67
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 65
def predecessor
siblings.previous(self) || parent
end
|
#source_code ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 36
def source_code
next_node_line =
if next_node
next_node.line - 1
else
@document.source_lines.count + 1
end
@document.source_lines[@line - 1...next_node_line]
.join("\n")
.gsub(/^\s*\z/m, '')
end
|
#subsequents ⇒ Object
80
81
82
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 80
def subsequents
siblings.subsequents(self)
end
|
#successor ⇒ Object
69
70
71
72
73
74
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 69
def successor
next_sibling = siblings.next(self)
return next_sibling if next_sibling
parent&.successor
end
|
#text ⇒ Object
84
85
86
|
# File 'lib/rails-route-checker/parsers/haml_parser/tree/node.rb', line 84
def text
@value[:text].to_s
end
|