class NestedStruct
Public: turns JSON into a deeply nested OpenStruct. Will find Hashes with Hashes and within Arrays.
Public Class Methods
new(json=Hash.new)
click to toggle source
# File lib/util/nested_struct.rb, line 4 def initialize(json=Hash.new) @table = {} json.each do |key, value| @table[key.to_sym] = if value.is_a? Hash self.class.new(value) elsif value.is_a? Array # Turn all the jsons in the array into DeepStructs value.collect do |i| i.is_a?(Hash) ? self.class.new(i) : i end else value end new_ostruct_member(key) end end
Public Instance Methods
as_json(*args)
click to toggle source
Calls superclass method
# File lib/util/nested_struct.rb, line 23 def as_json(*args) json = super json["table"] end