Class: HtmlDiff::Formatter

Inherits:
Object show all
Defined in:
lib/html_diff.rb

Instance Method Summary collapse

Constructor Details

#initializeFormatter

Returns a new instance of Formatter.



18
19
20
# File 'lib/html_diff.rb', line 18

def initialize
  @html = ''
end

Instance Method Details

#discard_a(event) ⇒ Object



27
28
29
30
# File 'lib/html_diff.rb', line 27

def discard_a(event)
  start(:"diff-delete") unless @state == :"diff-delete"
  @html << event.old_element
end

#discard_b(event) ⇒ Object



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

def discard_b(event)
  start(:"diff-add") unless @state == :"diff-add"
  @html << event.new_element
end

#finishObject



43
44
45
46
# File 'lib/html_diff.rb', line 43

def finish
  @html << '</span>' if @state
  @html
end

#match(event) ⇒ Object



22
23
24
25
# File 'lib/html_diff.rb', line 22

def match(event)
  start(:match) unless @state == :match
  @html << event.old_element
end

#start(state) ⇒ Object



37
38
39
40
41
# File 'lib/html_diff.rb', line 37

def start(state)
  finish unless @state == state
  @state = state
  @html << %Q(<span class="#{state}">)
end