class Diff::LCS::Block

A block is an operation removing, adding, or changing a group of items, a list of changes, where each change adds or deletes a single item.

Used by bin/ldiff.

Public Class Methods

# File lib/diff/lcs/block.rb, line 10
def self.from_chunk(chunk)
  changes, insert, remove = [], [], []

  chunk.each do
    changes << _1
    remove << _1 if _1.deleting?
    insert << _1 if _1.adding?
  end

  new(changes: changes.freeze, remove: remove.freeze, insert: insert.freeze)
end

Public Instance Methods

# File lib/diff/lcs/block.rb, line 28
  def diff_size = insert.size - remove.size

  def op
    case [remove, insert]
    # Unchanged
    in [[], []] then "^"
    # Delete
    in [_, []] then "-"
    # Insert
    in [[], _] then "+"
    # Conflict
    in [_, _] then "!"
    end
  end
end
# File lib/diff/lcs/block.rb, line 30
def op
  case [remove, insert]
  # Unchanged
  in [[], []] then "^"
  # Delete
  in [_, []] then "-"
  # Insert
  in [[], _] then "+"
  # Conflict
  in [_, _] then "!"
  end
end