Module: Factor::Common

Defined in:
lib/common/deep_struct.rb

Defined Under Namespace

Classes: DeepStruct

Class Method Summary collapse

Class Method Details

.flat_hash(h, f = [], g = {}) ⇒ Object



38
39
40
41
42
# File 'lib/common/deep_struct.rb', line 38

def self.flat_hash(h,f=[],g={})
  return g.update({ f=>h }) unless h.is_a? Hash
  h.each { |k,r| flat_hash(r,f+[k],g) }
  g
end

.simple_object_convert(item) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/common/deep_struct.rb', line 44

def self.simple_object_convert(item)
  if item.is_a?(Hash)
    Factor::Common::DeepStruct.new(item)
  elsif item.is_a?(Array)
    item.map do |i|
      simple_object_convert(i)
    end
  else
    item
  end
end