class RailsRouteChecker::Parsers::HamlParser::Tree::Node

Attributes

children[RW]
line[R]
parent[RW]
type[R]

Public Class Methods

new(document, parse_node) click to toggle source
# 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

Public Instance Methods

directives() click to toggle source
# 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() { |node| ... } click to toggle source
# 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() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 49
def inspect
  "#<#{self.class.name}>"
end
line_numbers() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 76
def next_node
  children.first || successor
end
predecessor() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 65
def predecessor
  siblings.previous(self) || parent
end
source_code() click to toggle source
# 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() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 80
def subsequents
  siblings.subsequents(self)
end
successor() click to toggle source
# 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() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 84
def text
  @value[:text].to_s
end

Private Instance Methods

siblings() click to toggle source
# File lib/rails-route-checker/parsers/haml_parser/tree/node.rb, line 90
def siblings
  @siblings ||= Siblings.new(parent ? parent.children : [self])
end