Class: Intersail::Rpdf::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rpdf/models/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Node



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rpdf/models/node.rb', line 18

def initialize(hash)
  @hash = hash

  @name = hash[:name]

  subtags = hash[:childs][:tag_node] if hash[:childs] && hash[:childs][:tag_node]

  if subtags.kind_of? Array
    @children = subtags.map{|c| Node.new(c)}
  elsif subtags.kind_of? Hash
    @children = [Node.new(subtags)]
  end
end

Instance Method Details

#[](index) ⇒ Object



14
15
16
# File 'lib/rpdf/models/node.rb', line 14

def [](index)
  @hash[index]
end

#childrenObject



7
8
9
# File 'lib/rpdf/models/node.rb', line 7

def children
  @children
end

#has_children?Boolean



10
11
12
# File 'lib/rpdf/models/node.rb', line 10

def has_children?
  @children && @children.respond_to?(:length) && @children.length>0
end

#nameObject



4
5
6
# File 'lib/rpdf/models/node.rb', line 4

def name
  @name
end