class SimpleTemplates::AST::Node

Parent class for a node in the AST. This class is not supposed to be instantiated.

@!attribute [r] contents

@return [String] the content of the node

@!attribute [r] pos

@return [Number] the position of the content in the input

@!attribute [r] allowed

@return [Boolean] if the node is allowed. (see allowed?)

Attributes

allowed[R]
contents[R]
pos[R]

Public Class Methods

new(contents, pos, allowed) click to toggle source

Initializes a new Node. Please note that this class is not supposed to be instantiated. @param contents [String] the content of the node @param pos [Numbers] the position of the content in the input @param allowed [Boolean] if the node is allowed

# File lib/simple_templates/AST/node.rb, line 22
def initialize(contents, pos, allowed)
  @contents = contents
  @pos      = pos
  @allowed  = allowed
end

Public Instance Methods

==(other) click to toggle source

Compares the node to other node by comparing the attributes of the objects. @param other [SimpleTemplates::AST::Node] @return [Boolean]

# File lib/simple_templates/AST/node.rb, line 32
def ==(other)
  contents == other.contents && pos == other.pos && allowed == other.allowed
end
allowed?() click to toggle source

Checks if the Node is allowed by returning the value in the class attribute allowed.

# File lib/simple_templates/AST/node.rb, line 38
def allowed?
  allowed
end
name() click to toggle source

Returns only the name of the class without the namespace. @return [String]

# File lib/simple_templates/AST/node.rb, line 44
def name
  self.class.to_s.split('::').last
end
render(context) click to toggle source

Not implemented method to render a Node that must be especialized by the class inheriting from this class. @param context [Hash{ Symbol => String }] @return [String] substituded contexts :nocov:

# File lib/simple_templates/AST/node.rb, line 53
def render(context)
  raise NotImplementedError
end