Class: Hedgelog::Normalizer
- Inherits:
-
Object
- Object
- Hedgelog::Normalizer
- Defined in:
- lib/hedgelog/normalizer.rb
Instance Method Summary collapse
- #normalize(data) ⇒ Object
- #normalize_array(array) ⇒ Object
- #normalize_hash(hash) ⇒ Object
- #normalize_struct(struct) ⇒ Object
Instance Method Details
#normalize(data) ⇒ Object
3 4 5 6 7 |
# 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) ⇒ Object
19 20 21 |
# File 'lib/hedgelog/normalizer.rb', line 19 def normalize_array(array) array.to_json end |
#normalize_hash(hash) ⇒ Object
13 14 15 16 17 |
# 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) ⇒ Object
9 10 11 |
# File 'lib/hedgelog/normalizer.rb', line 9 def normalize_struct(struct) normalize_hash(Hash[struct.each_pair.to_a]) end |