Class: CalendariumRomanum::CLI Private

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/calendarium-romanum/cli.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.

Implementation of the calendariumrom executable. Not loaded by default when you require the gem.

Instance Method Summary collapse

Instance Method Details

#calendarsObject

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.


50
51
52
# File 'lib/calendarium-romanum/cli.rb', line 50

def calendars
  Data.each {|c| puts c.siglum }
end

#cmp(a, 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.


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/calendarium-romanum/cli.rb', line 68

def cmp(a, b)
  loader = SanctoraleLoader.new
  paths = [a, b]
  sanctoralia = paths.collect {|source| loader.load_from_file source }
  names = paths.collect {|source| File.basename source }

  # a leap year must be chosen in order to iterate over
  # all possible days of a Sanctorale
  Year.new(1990).each_day do |d|
    a, b = sanctoralia.collect {|s| s.get(d) }

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

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

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

      differences = %i(rank colour symbol).select do |property|
        ca.public_send(property) != cb.public_send(property)
      end

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

#errors(*files) ⇒ 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.


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/calendarium-romanum/cli.rb', line 55

def errors(*files)
  loader = SanctoraleLoader.new
  files.each do |path|
    s = Sanctorale.new
    begin
      loader.load_from_file path, s
    rescue Errno::ENOENT, InvalidDataError => err
      die! err.message
    end
  end
end

#query(date_str = nil) ⇒ 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.


15
16
17
18
19
20
21
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
# File 'lib/calendarium-romanum/cli.rb', line 15

def query(date_str = nil)
  I18n.locale = options[:locale]
  calendar = options[:calendar]
  if File.exist?(calendar)
    begin
      sanctorale = SanctoraleLoader.new.load_from_file(calendar)
    rescue CalendariumRomanum::InvalidDataError
      die! 'Invalid file format.'
    end
  else
    data_file = Data[calendar]

    if data_file.nil?
      die! "Invalid calendar. Either loading a calendar from filesystem did not succeed, \n or a preinstalled calendar was specified which doesn't exist. See subcommand `calendars` for valid options."
    end
    sanctorale = data_file.load
  end

  pcal = PerpetualCalendar.new sanctorale: sanctorale

  if date_str
    begin
      parsed_date = DateParser.new(date_str)
      parsed_date.date_range.each do |day|
        print_single_date(pcal, day)
      end
    rescue ArgumentError
      die! 'Invalid date.'
    end
  else
    print_single_date(pcal, Date.today)
  end
end

#versionObject

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.


109
110
111
112
# File 'lib/calendarium-romanum/cli.rb', line 109

def version
  puts 'calendarium-romanum CLI'
  puts "calendarium-romanum: version #{CalendariumRomanum::VERSION}, released #{CalendariumRomanum::RELEASE_DATE}"
end