class Yoda::Parsing::NodeObjects::ConstNode

Attributes

node[R]

@param node [::AST::Node]

Public Class Methods

new(node) click to toggle source

@param node [::AST::Node]

# File lib/yoda/parsing/node_objects/const_node.rb, line 9
def initialize(node)
  fail ArgumentError, node unless node.is_a?(::AST::Node) && node.type == :const
  @node = node
end

Public Instance Methods

absolute?() click to toggle source

@return [true, false]

# File lib/yoda/parsing/node_objects/const_node.rb, line 20
def absolute?
  node.children.first == :cbase
end
just_after_separator?(location) click to toggle source

@param location [Location] @return [true, false]

# File lib/yoda/parsing/node_objects/const_node.rb, line 26
def just_after_separator?(location)
  return false unless node.location.double_colon
  location == Location.of_ast_location(node.location.double_colon.end)
end
parent_const() click to toggle source

@return [ConstNode, nil]

# File lib/yoda/parsing/node_objects/const_node.rb, line 15
def parent_const
  node.children.first && node.children.first.type == :const ? ConstNode.new(node.children.first) : nil
end
to_path() click to toggle source

@return [Model::Path]

# File lib/yoda/parsing/node_objects/const_node.rb, line 32
def to_path
  Model::Path.new(to_s)
end
to_s(base = nil) click to toggle source

@param base [String, Symbol, nil] @return [String]

# File lib/yoda/parsing/node_objects/const_node.rb, line 38
def to_s(base = nil)
  fail ArgumentError, base unless !base || base.is_a?(String) || base.is_a?(Symbol)
  paths = []
  looking_node = node
  while true
    return (base ? base.to_s + '::' : '') + paths.join('::') unless looking_node
    return '::' + paths.join('::') if looking_node.type == :cbase
    paths.unshift(looking_node.children[1])
    looking_node = looking_node.children[0]
  end
end