Class: HashPath

Inherits:
Object
  • Object
show all
Includes:
BBLib::Effortless
Defined in:
lib/bblib/core/hash_path/hash_path.rb,
lib/bblib/core/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



10
11
12
# File 'lib/bblib/core/hash_path/hash_path.rb', line 10

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

#find(hash) ⇒ Object



25
26
27
28
# 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) ⇒ Object



18
19
20
21
22
23
# 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) ⇒ Object



14
15
16
# File 'lib/bblib/core/hash_path/hash_path.rb', line 14

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