Class: Hedgelog::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/hedgelog/normalizer.rb

Instance Method Summary collapse

Instance Method Details

#normalize(data) ⇒ Object

rubocop:disable Security/MarshalLoad



4
5
6
7
8
# File 'lib/hedgelog/normalizer.rb', line 4

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) ⇒ Object



21
22
23
# File 'lib/hedgelog/normalizer.rb', line 21

def normalize_array(array)
  array.to_json
end

#normalize_hash(hash) ⇒ Object



15
16
17
18
19
# File 'lib/hedgelog/normalizer.rb', line 15

def normalize_hash(hash)
  Hash[hash.map do |key, val|
    [key, normalize_thing(val)]
  end]
end

#normalize_struct(struct) ⇒ Object

rubocop:enable Security/MarshalLoad



11
12
13
# File 'lib/hedgelog/normalizer.rb', line 11

def normalize_struct(struct)
  normalize_hash(Hash[struct.each_pair.to_a])
end