Class: Onde::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/onde.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aliasObject (readonly)

Returns the value of attribute alias.



97
98
99
# File 'lib/onde.rb', line 97

def alias
  @alias
end

#childrenObject (readonly)

Returns the value of attribute children.



97
98
99
# File 'lib/onde.rb', line 97

def children
  @children
end

#pathObject (readonly)

Returns the value of attribute path.



97
98
99
# File 'lib/onde.rb', line 97

def path
  @path
end