class SuperDiff::OperationTreeBuilders::Array::LcsCallbacks

Public Instance Methods

change(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 46
def change(event)
  children = compare.(event.old_element, event.new_element)

  if children
    add_change_operation(event, children)
  else
    add_delete_operation(event)
    add_insert_operation(event)
  end
end
discard_a(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 38
def discard_a(event)
  add_delete_operation(event)
end
discard_b(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 42
def discard_b(event)
  add_insert_operation(event)
end
match(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 34
def match(event)
  add_noop_operation(event)
end

Private Instance Methods

add_change_operation(event, children) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 89
def add_change_operation(event, children)
  operation_tree << 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,
    children: children,
  )
end
add_delete_operation(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 59
def add_delete_operation(event)
  operation_tree << Operations::UnaryOperation.new(
    name: :delete,
    collection: expected,
    key: event.old_position,
    value: event.old_element,
    index: event.old_position,
  )
end
add_insert_operation(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 69
def add_insert_operation(event)
  operation_tree << Operations::UnaryOperation.new(
    name: :insert,
    collection: actual,
    key: event.new_position,
    value: event.new_element,
    index: event.new_position,
  )
end
add_noop_operation(event) click to toggle source
# File lib/super_diff/operation_tree_builders/array.rb, line 79
def add_noop_operation(event)
  operation_tree << Operations::UnaryOperation.new(
    name: :noop,
    collection: actual,
    key: event.new_position,
    value: event.new_element,
    index: event.new_position,
  )
end