class CalendariumRomanum::CLI::Dumper

Produces a condensed text representation of a Calendar, used in regression tests. Not loaded by default by +require 'calendarium-romanum'+

@api private

Public Class Methods

new(io=STDOUT) click to toggle source
# File lib/calendarium-romanum/cli/dumper.rb, line 8
def initialize(io=STDOUT)
  @io = io
end

Public Instance Methods

call(calendar, *other_calendars) click to toggle source

Dumps calendar. If other_calendars are specified, dumps an alternative entry for any date for which any of other_calendars differs from calendar.

# File lib/calendarium-romanum/cli/dumper.rb, line 14
def call(calendar, *other_calendars)
  @io.puts "Calendar for liturgical year #{calendar.year}"
  calendar.each do |day|
    dump_day(day)

    other_calendars.each do |cal|
      day2 = cal[day.date]
      if day2 != day
        @io.print 'or '
        dump_day(day2)
      end
    end
  end
end
regression_tests_dump(year) click to toggle source

Produces the dump used for regression tests for the specified year.

# File lib/calendarium-romanum/cli/dumper.rb, line 30
def regression_tests_dump(year)
  sanctorale = Data::GENERAL_ROMAN_LATIN.load
  calendar = Calendar.new(
    year,
    sanctorale,
    vespers: true
  )
  calendar_with_transfers = Calendar.new(
    Temporale.new(year, transfer_to_sunday: Temporale::SUNDAY_TRANSFERABLE_SOLEMNITIES),
    sanctorale,
    vespers: true
  )
  calendar_with_extensions = Calendar.new(
    Temporale.new(year, extensions: Temporale::Extensions.all),
    sanctorale,
    vespers: true
  )

  I18n.with_locale(:la) do
    call(
      calendar,
      calendar_with_transfers,
      calendar_with_extensions,
    )
  end
end

Private Instance Methods

dump_day(day) click to toggle source
# File lib/calendarium-romanum/cli/dumper.rb, line 59
def dump_day(day)
  @io.puts [day.date, day.season.symbol, day.season_week, !day.vespers.nil?].join(' ')

  day.celebrations.each do |c|
    @io.puts ['-', c.title.inspect, c.rank.priority, c.colour.symbol, c.symbol, (c.date && "#{c.date.month}/#{c.date.day}"), c.cycle].join(' ')
  end
end