class Hedgelog::Normalizer
Public Instance Methods
normalize(data)
click to toggle source
# File lib/hedgelog/normalizer.rb, line 3 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
normalize_array(array)
click to toggle source
# File lib/hedgelog/normalizer.rb, line 19 def normalize_array(array) array.to_json end
normalize_hash(hash)
click to toggle source
# File lib/hedgelog/normalizer.rb, line 13 def normalize_hash(hash) Hash[hash.map do |key, val| [key, normalize_thing(val)] end] end
normalize_struct(struct)
click to toggle source
# File lib/hedgelog/normalizer.rb, line 9 def normalize_struct(struct) normalize_hash(Hash[struct.each_pair.to_a]) end
Private Instance Methods
normalize_thing(thing)
click to toggle source
# File lib/hedgelog/normalizer.rb, line 23 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