Class: Rapid::Template::Node::Root

Inherits:
Base
  • Object
show all
Defined in:
lib/rapid/template/node/root.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Base

#next_node, #static?

Constructor Details

#initialize(nodes) ⇒ Root

Returns a new instance of Root.



9
10
11
12
13
14
15
# File 'lib/rapid/template/node/root.rb', line 9

def initialize nodes
  @nodes = nodes
  
  nodes.each do |n|
    n.send :parent=, self
  end
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



7
8
9
# File 'lib/rapid/template/node/root.rb', line 7

def nodes
  @nodes
end

Instance Method Details

#==(obj) ⇒ Object



39
40
41
# File 'lib/rapid/template/node/root.rb', line 39

def == obj
  obj.is_a?(self.class) && obj.nodes == @nodes
end

#contentObject



35
36
37
# File 'lib/rapid/template/node/root.rb', line 35

def content
  nodes.first.content if nodes.first
end

#inspectObject



43
44
45
# File 'lib/rapid/template/node/root.rb', line 43

def inspect
  %(#<root nodes=#{@nodes.inspect}>)
end

#next_to(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rapid/template/node/root.rb', line 17

def next_to node
  # OPTIMIZE need object level eql? this the best way?
  index = nil
  nodes.each_with_index {|n, i| index = i if node.eql? n }
  return unless index
  
  node = nodes[index+1]
  return node if node
  
  parent.next_node if parent
end

#pull(result) ⇒ Object



29
30
31
32
33
# File 'lib/rapid/template/node/root.rb', line 29

def pull result
  @nodes.each do |node|
    node.pull result
  end
end