module CLIHelper::HashWithSearch

Hash with search

Public Instance Methods

dsearch(path) click to toggle source

Search inside path

@param path [String] Path to search on

# File lib/cli_helper.rb, line 276
def dsearch(path)
    stems = path.split('/')
    hash  = self

    stems.delete_if {|s| s.nil? || s.empty? }

    stems.each do |stem|
        if hash.is_a? Hash
            if hash[stem]
                hash = hash[stem]
            else
                hash = nil
                break
            end
        else
            hash = nil
            break
        end
    end

    hash
end