Class: Card::Diff::DiffBuilder::LCS

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

Defined Under Namespace

Classes: ExcludeeIterator, Summary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_text, new_text, opts, summary = nil) ⇒ LCS

Returns a new instance of LCS.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/card/diff.rb', line 100

def initialize old_text, new_text, opts, summary=nil
  @reject_pattern  = opts[:reject]        # regex; remove match completely from diff
  @exclude_pattern = opts[:exclude]       # regex; put back to the result after diff
  @preprocess      = opts[:preprocess]    # block; called with every word
  @postprocess     = opts[:postprocess]   # block; called with complete diff
  
  @adds_cnt = 0
  @dels_cnt = 0
  
  @splitters = %w( <[^>]+>  \[\[[^\]]+\]\]  \{\{[^}]+\}\}  \s+ )
  @disjunction_pattern = /^\s/ 
  @summary ||= Summary.new opts[:summary]
  if not old_text
    list = split_and_preprocess(new_text)
    if @exclude_pattern
      list = list.reject{ |word| word.match @exclude_pattern }
    end
    text = postprocess list.join
    @result = added_chunk text
    @summary.add text
  else
    init_diff old_text, new_text
    run_diff
  end
end

Instance Attribute Details

#adds_cntObject (readonly)

Returns the value of attribute adds_cnt.



99
100
101
# File 'lib/card/diff.rb', line 99

def adds_cnt
  @adds_cnt
end

#dels_cntObject (readonly)

Returns the value of attribute dels_cnt.



99
100
101
# File 'lib/card/diff.rb', line 99

def dels_cnt
  @dels_cnt
end

Instance Method Details

#completeObject



130
131
132
# File 'lib/card/diff.rb', line 130

def complete
  @result
end

#summaryObject



126
127
128
# File 'lib/card/diff.rb', line 126

def summary 
  @summary.result
end