class Imagen::Node::Base

Abstract base class

Attributes

ast_node[R]
children[R]
name[R]

Public Class Methods

new() click to toggle source
# File lib/imagen/node.rb, line 14
def initialize
  @children = []
end

Public Instance Methods

build_from_ast(ast_node) click to toggle source
# File lib/imagen/node.rb, line 22
def build_from_ast(ast_node)
  tap { @ast_node = ast_node }
end
file_path() click to toggle source
# File lib/imagen/node.rb, line 26
def file_path
  ast_node.location.name.source_buffer.name
end
find_all(matcher, ret = []) click to toggle source
# 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() click to toggle source
# File lib/imagen/node.rb, line 30
def first_line
  ast_node.location.first_line
end
human_name() click to toggle source
# File lib/imagen/node.rb, line 18
def human_name
  raise NotImplementedError
end
last_line() click to toggle source
# File lib/imagen/node.rb, line 38
def last_line
  ast_node.location.last_line
end
line_numbers() click to toggle source
# File lib/imagen/node.rb, line 34
def line_numbers
  (first_line..last_line).to_a
end
source() click to toggle source
# File lib/imagen/node.rb, line 42
def source
  source_lines.join("\n")
end
source_lines() click to toggle source
# 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() click to toggle source
# File lib/imagen/node.rb, line 46
def source_lines_with_numbers
  (first_line..last_line).zip(source_lines)
end