Method: Lipa::Node#[]

Defined in:
lib/lipa/node.rb

#[](path) ⇒ Node

Accessor for node by path in Unix style

Examples:

dir_2["dir_1/dir_2/searched_obj"] 
dir_2["searched_obj"] 
dir_2["./searched_obj"] 
dir_2["../dir_2/searched_obj"] 

Parameters:

  • path (String)

    nodes

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/lipa/node.rb', line 86

def [](path)
  split_path = path.split("/")   
  obj = case split_path[0]
  when ""
    @attrs[:tree]
  when ".."
    @attrs[:parent]
  when "."
    self
  else
    @attrs[:children][split_path[0].to_sym]
  end

  if obj
    if split_path.size > 1
      obj[split_path[1..-1].join("/")]
    else
      obj
    end
  end
end