Class: Palmister::StringSimpleCorrectionDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/palmister/string_simple_correction_diff.rb

Overview

require ‘action_view/template_handlers/erb’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStringSimpleCorrectionDiff

Returns a new instance of StringSimpleCorrectionDiff.



6
7
8
# File 'lib/palmister/string_simple_correction_diff.rb', line 6

def initialize
  @content = ""
end

Instance Attribute Details

#closingObject

:nodoc:



4
5
6
# File 'lib/palmister/string_simple_correction_diff.rb', line 4

def closing
  @closing
end

#contentObject

:nodoc:



4
5
6
# File 'lib/palmister/string_simple_correction_diff.rb', line 4

def content
  @content
end

#lastObject

:nodoc:



4
5
6
# File 'lib/palmister/string_simple_correction_diff.rb', line 4

def last
  @last
end

Instance Method Details

#change(event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/palmister/string_simple_correction_diff.rb', line 10

def change(event)
  if @last.nil?
    @content << %Q|<span class="change">|
  elsif @last != :change
    @content << %Q|#{closing}</span><span class="change">|
  end
  @content << %Q|<del class="only_a">#{event.old_element}</del><ins class="only_b">#{event.new_element.to_s}</ins>|
  @last = :change
  @closing = ""
end

#discard_a(event) ⇒ Object

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



34
35
36
37
38
39
40
41
42
43
# File 'lib/palmister/string_simple_correction_diff.rb', line 34

def discard_a(event)
  if @last.nil?
    @content << %Q|<span class="only_a"><del>|
  elsif @last != :only_a
    @content << %Q|#{closing}</span><span class="only_a"><del>|
  end
  @content << %Q|#{event.old_element.to_s}|
  @last = :only_a
  @closing = "</del>"
end

#discard_b(event) ⇒ Object

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



46
47
48
49
50
51
52
53
54
55
# File 'lib/palmister/string_simple_correction_diff.rb', line 46

def discard_b(event)
  if @last.nil?
    @content << %Q|<span class="only_b"><ins>|
  elsif @last != :only_b
    @content << %Q|#{closing}</span><span class="only_b"><ins>|
  end
  @content << %Q|#{event.new_element.to_s}|
  @last = :only_b
  @closing = "</ins>"
end

#match(event) ⇒ Object

This will be called with both lines are the same



22
23
24
25
26
27
28
29
30
31
# File 'lib/palmister/string_simple_correction_diff.rb', line 22

def match(event)
  if @last.nil?
    @content << %Q|<span class="match">|
  elsif @last != :match
    @content << %Q|#{closing}</span><span class="match">|
  end
  @content << event.old_element.to_s
  @last = :match
  @closing = ""
end