Class: Palmister::VcDiff
- Inherits:
-
Object
- Object
- Palmister::VcDiff
- Defined in:
- lib/palmister/vc_diff.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#last ⇒ Object
Returns the value of attribute last.
-
#last_lines ⇒ Object
Returns the value of attribute last_lines.
-
#new_line ⇒ Object
Returns the value of attribute new_line.
-
#old_line ⇒ Object
Returns the value of attribute old_line.
Instance Method Summary collapse
- #add_last_lines(n = 3) ⇒ Object
- #change(event) ⇒ Object
-
#discard_a(event) ⇒ Object
This will be called when there is a line in A that isn't in B.
-
#discard_b(event) ⇒ Object
This will be called when there is a line in B that isn't in A.
-
#initialize ⇒ VcDiff
constructor
A new instance of VcDiff.
-
#match(event) ⇒ Object
This will be called with both lines are the same.
Constructor Details
#initialize ⇒ VcDiff
Returns a new instance of VcDiff.
9 10 11 12 13 14 |
# File 'lib/palmister/vc_diff.rb', line 9 def initialize @content = "" @last_lines = [] @old_line = 1 @new_line = 1 end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
3 4 5 |
# File 'lib/palmister/vc_diff.rb', line 3 def content @content end |
#last ⇒ Object
Returns the value of attribute last
7 8 9 |
# File 'lib/palmister/vc_diff.rb', line 7 def last @last end |
#last_lines ⇒ Object
Returns the value of attribute last_lines
6 7 8 |
# File 'lib/palmister/vc_diff.rb', line 6 def last_lines @last_lines end |
#new_line ⇒ Object
Returns the value of attribute new_line
5 6 7 |
# File 'lib/palmister/vc_diff.rb', line 5 def new_line @new_line end |
#old_line ⇒ Object
Returns the value of attribute old_line
4 5 6 |
# File 'lib/palmister/vc_diff.rb', line 4 def old_line @old_line end |
Instance Method Details
#add_last_lines(n = 3) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/palmister/vc_diff.rb', line 50 def add_last_lines(n = 3) @content << %Q|<tr><td colspan="4">Next Change: </td></tr>\n| start = @last_lines.length - n start = 0 if start < 0 start.upto @last_lines.length do |i| @content << @last_lines[i] if @last_lines[i] end @last_lines = [] end |
#change(event) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/palmister/vc_diff.rb', line 16 def change(event) add_last_lines unless @last == :change @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n| @last = :change @old_line += 1 @new_line += 1 end |
#discard_a(event) ⇒ Object
This will be called when there is a line in A that isn't in B
33 34 35 36 37 38 39 |
# File 'lib/palmister/vc_diff.rb', line 33 def discard_a(event) add_last_lines unless @last == :discard_a @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td></td><td></td></tr>\n| @last = :discard_a @old_line += 1 end |
#discard_b(event) ⇒ Object
This will be called when there is a line in B that isn't in A
42 43 44 45 46 47 48 |
# File 'lib/palmister/vc_diff.rb', line 42 def discard_b(event) add_last_lines unless @last == :discard_b @content << %Q|<tr><td></td><td></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n| @last = :discard_b @new_line += 1 end |
#match(event) ⇒ Object
This will be called with both lines are the same
26 27 28 29 30 |
# File 'lib/palmister/vc_diff.rb', line 26 def match(event) @last_lines.push %Q|<tr><td>#{old_line}. </td><td colspan="2"><pre class="match">#{event.old_element}</pre></td><td>#{new_line}. </td></tr>\n| @old_line += 1 @new_line += 1 end |