Class: Cadenza::BlockNode

Inherits:
Object
  • Object
show all
Includes:
TreeNode
Defined in:
lib/cadenza/nodes/block_node.rb

Overview

The BlockNode is a general container with a given name meant to implement Cadenza's template inheritance feature. Blocks defined in a template will override the definition of blocks defined in the parent template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TreeNode

#to_tree

Constructor Details

#initialize(name, children = []) ⇒ BlockNode

creates a new block node with the given name and child nodes

Parameters:

  • name (String)

    the name for this block node

  • children (Array) (defaults to: [])

    the child nodes belonging to this block node


17
18
19
20
# File 'lib/cadenza/nodes/block_node.rb', line 17

def initialize(name, children=[])
   @name = name
   @children = children
end

Instance Attribute Details

#childrenArray

Returns the child nodes belonging to this block.

Returns:

  • (Array)

    the child nodes belonging to this block


12
13
14
# File 'lib/cadenza/nodes/block_node.rb', line 12

def children
  @children
end

#nameString

Returns the name of the node.

Returns:

  • (String)

    the name of the node


9
10
11
# File 'lib/cadenza/nodes/block_node.rb', line 9

def name
  @name
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns true if the given Cadenza::BlockNode is equivalent to the this node by value.

Parameters:

Returns:

  • (Boolean)

    true if the given Cadenza::BlockNode is equivalent to the this node by value.


31
32
33
34
# File 'lib/cadenza/nodes/block_node.rb', line 31

def ==(rhs)
   @name == rhs.name &&
   @children == rhs.children
end

#implied_globalsArray

Returns a list of any implied global variable names defined by this block's children.

Returns:

  • (Array)

    a list of any implied global variable names defined by this block's children.


24
25
26
# File 'lib/cadenza/nodes/block_node.rb', line 24

def implied_globals
   @children.map(&:implied_globals).flatten.uniq
end