Class: EncodingSampler::DiffCallbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/encoding_sampler/diff_callbacks.rb

Overview

Simple formatter to override Diff::LCS::DiffCallbacks in diff-lcs Gem to generate diffed output.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of EncodingSampler::DiffCallbacks.

Parameters:

  • options (Hash) (defaults to: {})

    Valid keys are :difference_start and :difference_end.

See Also:



27
28
29
30
31
32
# File 'lib/encoding_sampler/diff_callbacks.rb', line 27

def initialize(output, options = {})
  @output = output
  options ||= {}
  @difference_start = options[:difference_start] ||= '<span class="difference">'
  @difference_end = options[:difference_end] ||= '</span>'
end

Instance Attribute Details

#difference_endString (readonly)

Returns The string inserted in the diff results after a segment where the samples differ. Set as option on initialization.

Returns:

  • (String)

    The string inserted in the diff results after a segment where the samples differ. Set as option on initialization.



17
18
19
# File 'lib/encoding_sampler/diff_callbacks.rb', line 17

def difference_end
  @difference_end
end

#difference_startString (readonly)

Returns The string inserted in the diff results before a segment where the samples differ. Set as option on initialization.

Returns:

  • (String)

    The string inserted in the diff results before a segment where the samples differ. Set as option on initialization.



12
13
14
# File 'lib/encoding_sampler/diff_callbacks.rb', line 12

def difference_start
  @difference_start
end

#outputString

Returns Storage for the resultant diffed output.

Returns:

  • (String)

    Storage for the resultant diffed output.



12
13
14
# File 'lib/encoding_sampler/diff_callbacks.rb', line 12

def output
  @output
end

Instance Method Details

#discard_a(event) ⇒ Object

Called when there is a substring in A that isn't in B



40
41
42
# File 'lib/encoding_sampler/diff_callbacks.rb', line 40

def discard_a(event)
  output_changed event.old_element
end

#discard_b(event) ⇒ Object

Called when there is a substring in B that isn't in A



45
46
47
# File 'lib/encoding_sampler/diff_callbacks.rb', line 45

def discard_b(event)
  output_changed event.new_element
end

#match(event) ⇒ Object

Called with both strings are the same



35
36
37
# File 'lib/encoding_sampler/diff_callbacks.rb', line 35

def match(event)
  output_matched event.old_element
end