Class: CalendariumRomanum::CLI::Comparator Private

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/calendarium-romanum/cli/comparator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Compares two sanctorale data files, reports differences.

Constant Summary collapse

SUPPORTED_PROPERTIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i(rank colour symbol title)
DEFAULT_PROPERTIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

SUPPORTED_PROPERTIES - %i(title)

Instance Method Summary collapse

Methods included from Helper

#die!, #sanctorale_from_path

Constructor Details

#initialize(properties = DEFAULT_PROPERTIES) ⇒ Comparator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Comparator.



14
15
16
17
18
19
20
# File 'lib/calendarium-romanum/cli/comparator.rb', line 14

def initialize(properties = DEFAULT_PROPERTIES)
  unless Set.new(properties) <= Set.new(SUPPORTED_PROPERTIES)
    raise ArgumentError.new("Unsupported properties specified: #{properties} Only #{SUPPORTED_PROPERTIES} are supported")
  end

  @properties = properties
end

Instance Method Details

#call(path_a, path_b) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/calendarium-romanum/cli/comparator.rb', line 22

def call(path_a, path_b)
  paths = [path_a, path_b]
  sanctoralia = paths.collect {|source| sanctorale_from_path source }
  names = paths.collect {|source| File.basename source }

  differences_found = false
  all_possible_dates.each do |d|
    a, b = sanctoralia.collect {|sanctorale| sanctorale[d] }

    0.upto([a.size, b.size].max - 1) do |i|
      ca = a[i]
      cb = b[i]
      compared = [ca, cb]

      if compared.index(&:nil?)
        differences_found = true
        notnili = compared.index {|c| !c.nil? }

        print date(d)
        puts " only in #{names[notnili]}:"
        puts celebration(compared[notnili])
        puts
        next
      end

      differences = @properties.select do |property|
        ca.public_send(property) != cb.public_send(property)
      end

      next if differences.empty?
      differences_found = true
      print date(d)
      puts " differs in #{differences.join(', ')}"
      puts celebration(ca)
      puts celebration(cb)
      puts
    end
  end

  !differences_found
end