Class: DeepLDiff::Linearizer

Inherits:
Object
  • Object
show all
Defined in:
lib/deepl_diff/linearizer.rb

Class Method Summary collapse

Class Method Details

.linearize(struct, array = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/deepl_diff/linearizer.rb', line 5

def linearize(struct, array = [])
  case struct
  when Hash
    struct.each { |_k, v| linearize(v, array) }
  when Array
    struct.each { |v| linearize(v, array) }
  else
    array << struct
  end

  array
end

.restore(struct, array) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/deepl_diff/linearizer.rb', line 18

def restore(struct, array)
  case struct
  when Hash
    struct.transform_values { |v| restore(v, array) }
  when Array
    struct.map { |v| restore(v, array) }
  else
    array.shift
  end
end