Method: CloudDrive::Node#find_by_path

Defined in:
lib/clouddrive/node.rb

#find_by_path(path) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/clouddrive/node.rb', line 196

def find_by_path(path)
  path = path.gsub(/\A\//, '')
  path = path.gsub(/\/$/, '')
  path_info = Pathname.new(path)

  found_nodes = find_by_name(path_info.basename.to_s)
  if found_nodes.empty?
    return nil
  end

  match = nil
  found_nodes.each do |node|
    if build_node_path(node) == path
      match = node
    end
  end

  match
end