Class: Onde::Node
- Inherits:
-
Object
- Object
- Onde::Node
- Defined in:
- lib/onde.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(data, parent_path = nil) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(data, parent_path = nil) ⇒ Node
Returns a new instance of Node.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/onde.rb', line 99 def initialize(data, parent_path=nil) unless data.is_a? Array raise Onde::ConfigurationError.new("Node #{data} is not properly formed") end node_data, child_data = data if node_data.is_a? Hash @alias = node_data.keys()[0] path_part = node_data[@alias] elsif node_data.is_a? String @alias = nil path_part = node_data else raise Onde::ConfigurationError.new("Node #{data} is not properly formed") end @path = parent_path.nil? ? path_part : File.join(parent_path, path_part) child_data ||= [] @children = child_data.map do |child_data| Onde::Node.new(child_data, @path) end end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
97 98 99 |
# File 'lib/onde.rb', line 97 def alias @alias end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
97 98 99 |
# File 'lib/onde.rb', line 97 def children @children end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
97 98 99 |
# File 'lib/onde.rb', line 97 def path @path end |