Class: BBLib::PathHash
- Inherits:
-
BasicObject
- Defined in:
- lib/hash/path_hash.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ PathHash
Returns a new instance of PathHash.
15
16
17
|
# File 'lib/hash/path_hash.rb', line 15
def initialize hash
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(arg, formula = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/hash/path_hash.rb', line 46
def method_missing arg, formula = nil
arg = (@recursive ? "..#{arg}" : arg.to_s) +
(formula ? "(#{formula})" : '')
if @hash.is_a?(::Array)
PathHash.new @hash.map{ |h| if h.is_a?(::Array) || h.is_a?(::Hash) then h.hash_path(arg) end }.flatten(1)
else
PathHash.new @hash.hpath(arg)
end
end
|
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
13
14
15
|
# File 'lib/hash/path_hash.rb', line 13
def hash
@hash
end
|
#recursive ⇒ Object
Returns the value of attribute recursive.
13
14
15
|
# File 'lib/hash/path_hash.rb', line 13
def recursive
@recursive
end
|
Instance Method Details
#[](val) ⇒ Object
19
20
21
|
# File 'lib/hash/path_hash.rb', line 19
def [] val
PathHash.new(@hash.map{ |h| h[val]} )
end
|
#_ ⇒ Object
35
36
37
38
|
# File 'lib/hash/path_hash.rb', line 35
def _
@recursive = true
self
end
|
#_fval ⇒ Object
Also known as:
_f
29
30
31
|
# File 'lib/hash/path_hash.rb', line 29
def _fval
@hash.first rescue @hash
end
|
#_path(arg, formula = nil) ⇒ Object
40
41
42
|
# File 'lib/hash/path_hash.rb', line 40
def _path arg, formula = nil
method_missing arg, formula
end
|
#_val ⇒ Object
Also known as:
_v
23
24
25
|
# File 'lib/hash/path_hash.rb', line 23
def _val
@hash
end
|