class RichText::Diff

@api private

Attributes

chunks[R]

Public Class Methods

new(left, right) { |c| ... } click to toggle source
# File lib/rich-text/diff.rb, line 8
def initialize(left, right)
  @chunks = []
  ::Diff::LCS.traverse_sequences(left.to_plaintext, right.to_plaintext, self)
  @chunks.each { |c| yield c } if block_given?
end

Public Instance Methods

discard_a(args) click to toggle source
# File lib/rich-text/diff.rb, line 26
def discard_a(args)
  push :delete
end
discard_b(args) click to toggle source
# File lib/rich-text/diff.rb, line 30
def discard_b(args)
  push :insert
end
match(args) click to toggle source
# File lib/rich-text/diff.rb, line 22
def match(args)
  push :retain
end
push(type) click to toggle source
# File lib/rich-text/diff.rb, line 14
def push(type)
  if @chunks.any? && @chunks[-1][0] == type
    @chunks[-1][1] += 1
  else
    @chunks.push [type, 1]
  end
end