Class: RichText::Diff Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rich-text/diff.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Diff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Diff.



8
9
10
11
12
# 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

Instance Attribute Details

#chunksObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/rich-text/diff.rb', line 6

def chunks
  @chunks
end

Instance Method Details

#discard_a(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/rich-text/diff.rb', line 26

def discard_a(args)
  push :delete
end

#discard_b(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/rich-text/diff.rb', line 30

def discard_b(args)
  push :insert
end

#match(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/rich-text/diff.rb', line 22

def match(args)
  push :retain
end

#push(type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
# 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