Module: Canon::Comparison::BaseComparator

Defined in:
lib/canon/comparison/base_comparator.rb

Overview

Base module for comparators providing common patterns Each comparator should include this module and implement:

  • serialize_for_display(content, match_opts)

Instance Method Summary collapse

Instance Method Details

#build_verbose_result(differences, content1, content2, match_opts) ⇒ Hash

Build verbose result hash with preprocessed strings

Parameters:

  • differences (Array)

    Array of difference hashes

  • content1 (Object)

    First content to compare

  • content2 (Object)

    Second content to compare

  • match_opts (Hash)

    Match options used during comparison

Returns:

  • (Hash)

    Hash with :differences and :preprocessed keys



16
17
18
19
20
21
22
23
24
# File 'lib/canon/comparison/base_comparator.rb', line 16

def build_verbose_result(differences, content1, content2, match_opts)
  {
    differences: differences,
    preprocessed: [
      serialize_for_display(content1, match_opts),
      serialize_for_display(content2, match_opts),
    ],
  }
end

#serialize_for_display(content, match_opts) ⇒ String

Serialize content for display in diffs This method must be implemented by each comparator

Parameters:

  • content (Object)

    Content to serialize

  • match_opts (Hash)

    Match options that were applied during comparison

Returns:

  • (String)

    Serialized content reflecting match options

Raises:

  • (NotImplementedError)

    if not implemented by including class



33
34
35
36
# File 'lib/canon/comparison/base_comparator.rb', line 33

def serialize_for_display(content, match_opts)
  raise NotImplementedError,
        "#{self.class.name} must implement serialize_for_display"
end