Class: Card::Diff::LCS

Inherits:
Object show all
Defined in:
lib/card/diff/lcs.rb

Overview

Use LCS algorithm to create a Diff::Result

Defined Under Namespace

Classes: ChunkProcessor, ExcludeeIterator

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ LCS

Returns a new instance of LCS.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/card/diff/lcs.rb', line 5

def initialize opts
  # regex; remove matches completely from diff
  @reject_pattern = opts[:reject]
  # regex; put matches back to the result after diff
  @exclude_pattern = opts[:exclude]

  @preprocess   = opts[:preprocess]  # block; called with every word
  @postprocess  = opts[:postprocess] # block; called with complete diff

  @splitters = %w( <[^>]+>  \[\[[^\]]+\]\]  \{\{[^}]+\}\}  \s+ )
  @disjunction_pattern = /^\s/
end

Instance Method Details

#run(old_text, new_text, result) ⇒ Object



18
19
20
21
22
# File 'lib/card/diff/lcs.rb', line 18

def run old_text, new_text, result
  @result = result
  compare old_text, new_text
  @result.complete = postprocess @result.complete
end