Class: WCC::InLineDiffer
- Inherits:
-
Object
- Object
- WCC::InLineDiffer
- Defined in:
- lib/wcc/diff.rb
Overview
Calculates hilite based on per char side-by-side diff for two DiffItems.
Instance Method Summary collapse
- #change(e) ⇒ Object
- #compute_hilite ⇒ Object
- #discard_a(e) ⇒ Object
- #discard_b(e) ⇒ Object
-
#initialize(a, b) ⇒ InLineDiffer
constructor
A new instance of InLineDiffer.
- #match(e) ⇒ Object
Constructor Details
#initialize(a, b) ⇒ InLineDiffer
Returns a new instance of InLineDiffer.
159 160 161 162 163 164 |
# File 'lib/wcc/diff.rb', line 159 def initialize(a, b) @a = a @b = b @a.hilite = [] @b.hilite = [] end |
Instance Method Details
#change(e) ⇒ Object
185 186 187 188 |
# File 'lib/wcc/diff.rb', line 185 def change(e) @a.hilite << e.old_position if not @a.hilite.include?(e.old_position) @b.hilite << e.new_position if not @b.hilite.include?(e.new_position) end |
#compute_hilite ⇒ Object
166 167 168 169 170 171 |
# File 'lib/wcc/diff.rb', line 166 def compute_hilite #puts @a.text.chars.to_a.inspect #puts @b.text.chars.to_a.inspect # HACK: Diff::LCS with plain strings fails on Ruby 1.8 even with -Ku flag but not: <string>.chars.to_a Diff::LCS.traverse_balanced(@a.text.chars.to_a, @b.text.chars.to_a, self) end |
#discard_a(e) ⇒ Object
177 178 179 |
# File 'lib/wcc/diff.rb', line 177 def discard_a(e) @a.hilite << e.old_position if not @a.hilite.include?(e.old_position) end |
#discard_b(e) ⇒ Object
181 182 183 |
# File 'lib/wcc/diff.rb', line 181 def discard_b(e) @b.hilite << e.new_position if not @b.hilite.include?(e.new_position) end |
#match(e) ⇒ Object
173 174 175 |
# File 'lib/wcc/diff.rb', line 173 def match(e) # don't care end |