Class: Ruote::XmlReader::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/reader/xml.rb

Overview

A helper class to store the temporary tree while it gets read.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, attributes) ⇒ Node

Returns a new instance of Node.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruote/reader/xml.rb', line 50

def initialize(parent, name, attributes)

  @parent = parent
  @name = name
  @attributes = attributes.inject({}) { |h, (k, v)|
    h[k.gsub(/-/, '_')] = v
    h
  }
  @children = []

  parent.children << self if parent
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



48
49
50
# File 'lib/ruote/reader/xml.rb', line 48

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



48
49
50
# File 'lib/ruote/reader/xml.rb', line 48

def children
  @children
end

#parentObject (readonly)

Returns the value of attribute parent.



48
49
50
# File 'lib/ruote/reader/xml.rb', line 48

def parent
  @parent
end

Instance Method Details

#to_aObject



63
64
65
66
# File 'lib/ruote/reader/xml.rb', line 63

def to_a

  [ @name, @attributes, @children.collect { |c| c.to_a } ]
end