Class: Diff::LCS::HTMLDiff::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/diff/lcs/htmldiff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ Callbacks

Returns a new instance of Callbacks.



17
18
19
20
21
22
23
24
# File 'lib/diff/lcs/htmldiff.rb', line 17

def initialize(output, options = {})
  @output = output
  options ||= {}

  @match_class = options[:match_class] || "match"
  @only_a_class = options[:only_a_class] || "only_a"
  @only_b_class = options[:only_b_class] || "only_b"
end

Instance Attribute Details

#match_classObject

Returns the value of attribute match_class.



13
14
15
# File 'lib/diff/lcs/htmldiff.rb', line 13

def match_class
  @match_class
end

#only_a_classObject

Returns the value of attribute only_a_class.



14
15
16
# File 'lib/diff/lcs/htmldiff.rb', line 14

def only_a_class
  @only_a_class
end

#only_b_classObject

Returns the value of attribute only_b_class.



15
16
17
# File 'lib/diff/lcs/htmldiff.rb', line 15

def only_b_class
  @only_b_class
end

#outputObject

Returns the value of attribute output.



12
13
14
# File 'lib/diff/lcs/htmldiff.rb', line 12

def output
  @output
end

Instance Method Details

#discard_a(event) ⇒ Object

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



38
39
40
# File 'lib/diff/lcs/htmldiff.rb', line 38

def discard_a(event)
  @output << htmlize(event.old_element, :only_a_class)
end

#discard_b(event) ⇒ Object

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



43
44
45
# File 'lib/diff/lcs/htmldiff.rb', line 43

def discard_b(event)
  @output << htmlize(event.new_element, :only_b_class)
end

#match(event) ⇒ Object

This will be called with both lines are the same



33
34
35
# File 'lib/diff/lcs/htmldiff.rb', line 33

def match(event)
  @output << htmlize(event.old_element, :match_class)
end