Class: Output::SimpleHtmlDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/output/simple_html_diff.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimpleHtmlDiff

Returns a new instance of SimpleHtmlDiff.



6
7
8
9
10
# File 'lib/output/simple_html_diff.rb', line 6

def initialize
  @content = ""
  @old_line = 1
  @new_line = 1
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



2
3
4
# File 'lib/output/simple_html_diff.rb', line 2

def content
  @content
end

#new_lineObject

Returns the value of attribute new_line.



4
5
6
# File 'lib/output/simple_html_diff.rb', line 4

def new_line
  @new_line
end

#old_lineObject

Returns the value of attribute old_line.



3
4
5
# File 'lib/output/simple_html_diff.rb', line 3

def old_line
  @old_line
end

Instance Method Details

#change(event) ⇒ Object



12
13
14
15
16
# File 'lib/output/simple_html_diff.rb', line 12

def change(event)
  @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|
  @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



26
27
28
29
# File 'lib/output/simple_html_diff.rb', line 26

def discard_a(event)
  @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td></td><td></td></tr>\n|
  @old_line += 1
end

#discard_b(event) ⇒ Object

This will be called when there is a line in B that isn’t in A



32
33
34
35
# File 'lib/output/simple_html_diff.rb', line 32

def discard_b(event)
  @content << %Q|<tr><td></td><td></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
  @new_line += 1
end

#match(event) ⇒ Object

This will be called with both lines are the same



19
20
21
22
23
# File 'lib/output/simple_html_diff.rb', line 19

def match(event)
  @content << %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