Class: NeptuneCoffee::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/neptune_coffee/util.rb

Class Method Summary collapse

Class Method Details

.deep_length(data) ⇒ Object

returns number of hash and array elements recursively



15
16
17
18
19
20
21
# File 'lib/neptune_coffee/util.rb', line 15

def deep_length data
  case data
  when Hash  then data.length + data.inject(0) {|sum,v| sum + deep_length(v[1])}
  when Array then data.length + data.inject(0) {|sum,v| sum + deep_length(v)}
  else 0
  end
end

.subdir_hash(path) ⇒ Object

returns a hash of path’s subdirectories mapped to recursive calls on subdir_hash on those subdirs



6
7
8
9
10
11
12
# File 'lib/neptune_coffee/util.rb', line 6

def subdir_hash path
  result = {}
  path.children.each do |c|
    result[c] = subdir_hash c if c.directory?
  end
  result
end