Class: Card::Content::Diff::LCS

Inherits:
Object
  • Object
show all
Defined in:
lib/card/content/diff/lcs.rb,
lib/card/content/diff/processor.rb

Overview

Use LCS algorithm to create a Diff::Result

Defined Under Namespace

Classes: ExcludeeIterator, Processor

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ LCS

Returns a new instance of LCS.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/card/content/diff/lcs.rb', line 8

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



21
22
23
24
25
# File 'lib/card/content/diff/lcs.rb', line 21

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