Class: CalendariumRomanum::CLI

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

Instance Method Summary collapse

Instance Method Details

#calendarsObject



48
49
50
# File 'lib/calendarium-romanum/cli.rb', line 48

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

#cmp(a, b) ⇒ Object



62
63
64
65
66
67
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
# File 'lib/calendarium-romanum/cli.rb', line 62

def cmp(a, b)
  loader = SanctoraleLoader.new
  sanctorales = []

  [a, b].each do |source|
    s = Sanctorale.new
    loader.load_from_file source, s
    sanctorales << s
  end

  # a leap year must be chosen in order to iterate over
  # all possible days of a Sanctorale
  Year.new(1990).each_day do |d|
    celebs = sanctorales.collect {|s| s.get d.month, d.day }
    if celebs.find {|cc| cc.nil? }
      next
    end

    celebs[0].each_index do |i|
      if i >= celebs[1].size
        break
      end

      ca = celebs[0][i]
      cb = celebs[1][i]

      if ca.rank != cb.rank || ca.colour != cb.colour
        puts "#{d.month}/#{d.day}"
        print_celebration ca
        print_celebration cb
        puts
      end
    end
  end
end

#errors(*files) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/calendarium-romanum/cli.rb', line 53

def errors(*files)
  loader = SanctoraleLoader.new
  files.each do |path|
    s = Sanctorale.new
    loader.load_from_file path, s
  end
end

#query(date_str = nil) ⇒ Object



11
12
13
14
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
# File 'lib/calendarium-romanum/cli.rb', line 11

def query(date_str=nil)
  I18n.locale = options[:locale]

  data_file = Data[options[:calendar]]
  if data_file.nil?
    STDERR.puts 'Invalid calendar. See subcommand `calendars` for valid options.'
    exit 1
  end
  sanctorale = data_file.load

  date =
    if date_str
      begin
        Date.parse(date_str)
      rescue ArgumentError
        STDERR.puts 'Invalid date.'
        exit 1
      end
    else
      Date.today
    end
  calendar = Calendar.for_day(date, sanctorale)
  day = calendar.day date

  puts date
  puts "season: #{day.season}"
  puts

  rank_length = day.celebrations.collect {|c| c.rank.short_desc.size }.max
  day.celebrations.each do |c|
    print c.rank.short_desc.rjust(rank_length)
    print ' : '
    puts c.title
  end
end