Class: SuperDiff::OperationalSequencers::Array::LcsCallbacks

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected:, actual:, extra_operational_sequencer_classes:, extra_diff_formatter_classes:) ⇒ LcsCallbacks

Returns a new instance of LcsCallbacks.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/super_diff/operational_sequencers/array.rb', line 31

def initialize(
  expected:,
  actual:,
  extra_operational_sequencer_classes:,
  extra_diff_formatter_classes:
)
  @expected = expected
  @actual = actual
  @operations = OperationSequences::Array.new([])
  @extra_operational_sequencer_classes =
    extra_operational_sequencer_classes
  @extra_diff_formatter_classes = extra_diff_formatter_classes
end

Instance Attribute Details

#operationsObject (readonly)

Returns the value of attribute operations.



29
30
31
# File 'lib/super_diff/operational_sequencers/array.rb', line 29

def operations
  @operations
end

Instance Method Details

#change(event) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/super_diff/operational_sequencers/array.rb', line 75

def change(event)
  child_operations = sequence(event.old_element, event.new_element)

  if child_operations
    operations << ::SuperDiff::Operations::BinaryOperation.new(
      name: :change,
      left_collection: expected,
      right_collection: actual,
      left_key: event.old_position,
      right_key: event.new_position,
      left_value: event.old_element,
      right_value: event.new_element,
      left_index: event.old_position,
      right_index: event.new_position,
      child_operations: child_operations,
    )
  else
    operations << Operations::UnaryOperation.new(
      name: :delete,
      collection: expected,
      key: event.old_position,
      value: event.old_element,
      index: event.old_position,
    )
    operations << Operations::UnaryOperation.new(
      name: :insert,
      collection: actual,
      key: event.new_position,
      value: event.new_element,
      index: event.new_position,
    )
  end
end

#discard_a(event) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/super_diff/operational_sequencers/array.rb', line 55

def discard_a(event)
  operations << ::SuperDiff::Operations::UnaryOperation.new(
    name: :delete,
    collection: expected,
    key: event.old_position,
    value: event.old_element,
    index: event.old_position,
  )
end

#discard_b(event) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/super_diff/operational_sequencers/array.rb', line 65

def discard_b(event)
  operations << ::SuperDiff::Operations::UnaryOperation.new(
    name: :insert,
    collection: actual,
    key: event.new_position,
    value: event.new_element,
    index: event.new_position,
  )
end

#match(event) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/super_diff/operational_sequencers/array.rb', line 45

def match(event)
  operations << ::SuperDiff::Operations::UnaryOperation.new(
    name: :noop,
    collection: actual,
    key: event.new_position,
    value: event.new_element,
    index: event.new_position,
  )
end