Class: HashPath

Inherits:
Object
  • Object
show all
Includes:
BBLib::Effortless
Defined in:
lib/hash_path/hash_path.rb,
lib/hash_path/part.rb

Overview

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.

Defined Under Namespace

Classes: Part

Instance Method Summary collapse

Methods included from BBLib::Effortless

#_attrs, included

Instance Method Details

#append(path) ⇒ Object



12
13
14
# File 'lib/hash_path/hash_path.rb', line 12

def append(path)
  insert(path, parts.size)
end

#find(hash) ⇒ Object



27
28
29
30
# File 'lib/hash_path/hash_path.rb', line 27

def find(hash)
  hash = TreeHash.new unless hash.is_a?(TreeHash)
  hash.find(self)
end

#insert(path, index) ⇒ Object



20
21
22
23
24
25
# File 'lib/hash_path/hash_path.rb', line 20

def insert(path, index)
  parse_path(path).each do |part|
    parts[index] = part
    index += 1
  end
end

#prepend(path) ⇒ Object



16
17
18
# File 'lib/hash_path/hash_path.rb', line 16

def prepend(path)
  insert(path, 0)
end