Class: Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-d2l/tools.rb

Class Method Summary collapse

Class Method Details

._get_all_values_nested(nested_hash = {}, path = []) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby-d2l/tools.rb', line 27

def self._get_all_values_nested(nested_hash={}, path=[])
    all_values = {}
    nested_hash.each_pair do |k,v|
      path << k
      case v
        when Array, Date, DateTime, FalseClass, Fixnum, NilClass, String, TrueClass then
          all_values.merge!({"#{path.join(".")}" => "#{v}"})
        when Hash then
          all_values.merge!(_get_all_values_nested(v, path))
        else
          raise ArgumentError, "Unhandled type #{v.class}"
      end
      path.pop
     end
     return all_values
end

.get_all_values_nested(nested_hash = {}) ⇒ Object

def self.get_all_values_nested(nested_hash={})

@all_values = {}

nested_hash.each_pair do |k,v|
  @path << k
  case v
    when Array, DateTime, FalseClass, Fixnum, NilClass, String, TrueClass then 
      @all_values.merge!({"#{@path.join(".")}" => "#{v}"}) 
      @path.pop
    when Hash then get_all_values_nested(v)
    else raise ArgumentError, "Unhandled type #{v.class}"
  end
end
@path.pop

return @all_values

end



23
24
25
# File 'lib/ruby-d2l/tools.rb', line 23

def self.get_all_values_nested(nested_hash={})
    @all_values = _get_all_values_nested(nested_hash)
end