Class: SuperDiff::OperationalSequencers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/operational_sequencers/base.rb

Direct Known Subclasses

Array, Hash, MultiLineString, Object

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected:, actual:, extra_operational_sequencer_classes: [], extra_diff_formatter_classes: []) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/super_diff/operational_sequencers/base.rb', line 12

def initialize(
  expected:,
  actual:,
  extra_operational_sequencer_classes: [],
  extra_diff_formatter_classes: []
)
  @expected = expected
  @actual = actual
  @extra_operational_sequencer_classes =
    extra_operational_sequencer_classes
  @extra_diff_formatter_classes = extra_diff_formatter_classes
end

Class Method Details

.applies_to?(_value) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


4
5
6
# File 'lib/super_diff/operational_sequencers/base.rb', line 4

def self.applies_to?(_value)
  raise NotImplementedError
end

.call(*args) ⇒ Object



8
9
10
# File 'lib/super_diff/operational_sequencers/base.rb', line 8

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/super_diff/operational_sequencers/base.rb', line 25

def call
  i = 0
  operations = operation_sequence_class.new([])

  while i < unary_operations.length
    operation = unary_operations[i]
    next_operation = unary_operations[i + 1]
    child_operations = possible_comparison_of(operation, next_operation)

    if child_operations
      operations << Operations::BinaryOperation.new(
        name: :change,
        left_collection: operation.collection,
        right_collection: next_operation.collection,
        left_key: operation.key,
        right_key: operation.key,
        left_value: operation.collection[operation.key],
        right_value: next_operation.collection[operation.key],
        left_index: operation.index,
        right_index: operation.index,
        child_operations: child_operations,
      )
      i += 2
    else
      operations << operation
      i += 1
    end
  end

  operations
end