Sha256: e010302b5d7e507fa723cb9f0af82d87154b220fc0018f551024f9ba11111b47
Contents?: true
Size: 853 Bytes
Versions: 2
Compression:
Stored size: 853 Bytes
Contents
class Hedgelog class Normalizer def normalize(data) # Need to Marshal.dump/Marshal.load to deep copy the input so that scrubbing doesn't change global state d = Marshal.load(Marshal.dump(data)) normalize_hash(d) end def normalize_struct(struct) normalize_hash(Hash[struct.each_pair.to_a]) end def normalize_hash(hash) Hash[hash.map do |key, val| [key, normalize_thing(val)] end] end def normalize_array(array) array.to_json end private def normalize_thing(thing) return '' if thing.nil? thing = thing.as_json if thing.respond_to?(:as_json) return normalize_struct(thing) if thing.is_a?(Struct) return normalize_array(thing) if thing.is_a?(Array) return normalize_hash(thing) if thing.is_a?(Hash) thing end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hedgelog-0.1.8 | lib/hedgelog/normalizer.rb |
hedgelog-0.1.7 | lib/hedgelog/normalizer.rb |