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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/card/diff.rb', line 92

def initialize old_text, new_text, opts, _summary=nil
  # regex; remove match completely from diff
  @reject_pattern  = opts[:reject]

  # regex; put 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

  @adds_cnt = 0
  @dels_cnt = 0

  @splitters = %w( <[^>]+>  \[\[[^\]]+\]\]  \{\{[^}]+\}\}  \s+ )
  @disjunction_pattern = /^\s/
  @summary ||= Summary.new opts[:summary]
  if !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.



91
92
93
# File 'lib/card/diff.rb', line 91

def adds_cnt
  @adds_cnt
end

#dels_cntObject (readonly)

Returns the value of attribute dels_cnt.



91
92
93
# File 'lib/card/diff.rb', line 91

def dels_cnt
  @dels_cnt
end

Instance Method Details

#completeObject



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

def complete
  @result
end

#summaryObject



122
123
124
# File 'lib/card/diff.rb', line 122

def summary
  @summary.result
end