class HashPath
This classes parses dot delimited hash path strings and wraps the corresponding parts. Then hashes or arrays can be passed to the find method to find all matching elements for the path.
Public Instance Methods
append(path)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 10 def append(path) insert(path, parts.size) end
find(hash)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 25 def find(hash) hash = TreeHash.new unless hash.is_a?(TreeHash) hash.find(self) end
insert(path, index)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 18 def insert(path, index) parse_path(path).each do |part| parts[index] = part index += 1 end end
prepend(path)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 14 def prepend(path) insert(path, 0) end
Protected Instance Methods
parse_path(path)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 38 def parse_path(path) path.to_s.gsub('..', '.[[:recursive:]]').scan(/(?:[\(|\[|\/].*?[\)|\]|\/]|\\\.|[^\.])+/).map do |part| Part.new(part) end end
simple_init(*args)
click to toggle source
# File lib/bblib/core/hash_path/hash_path.rb, line 32 def simple_init(*args) args.find_all { |arg| arg.is_a?(String) || arg.is_a?(Symbol) }.each do |path| append(path.to_s) end end