Class: EncodingSampler::DiffCallbacks
- Inherits:
-
Object
- Object
- EncodingSampler::DiffCallbacks
- 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
-
#difference_end ⇒ String
readonly
The string inserted in the diff results after a segment where the samples differ.
-
#difference_start ⇒ String
readonly
The string inserted in the diff results before a segment where the samples differ.
-
#output ⇒ String
Storage for the resultant diffed output.
Instance Method Summary collapse
-
#discard_a(event) ⇒ Object
Called when there is a substring in A that isn't in B.
-
#discard_b(event) ⇒ Object
Called when there is a substring in B that isn't in A.
-
#initialize(output, options = {}) ⇒ DiffCallbacks
constructor
Returns a new instance of EncodingSampler::DiffCallbacks.
-
#match(event) ⇒ Object
Called with both strings are the same.
Constructor Details
#initialize(output, options = {}) ⇒ DiffCallbacks
Returns a new instance of EncodingSampler::DiffCallbacks.
27 28 29 30 31 32 |
# File 'lib/encoding_sampler/diff_callbacks.rb', line 27 def initialize(output, = {}) @output = output ||= {} @difference_start = [:difference_start] ||= '<span class="difference">' @difference_end = [:difference_end] ||= '</span>' end |
Instance Attribute Details
#difference_end ⇒ String (readonly)
Returns 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_start ⇒ String (readonly)
Returns 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 |
#output ⇒ String
Returns 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 |