lib/calrom/formatter/overview.rb in calrom-0.3.0 vs lib/calrom/formatter/overview.rb in calrom-0.4.0

- old
+ new

@@ -2,23 +2,23 @@ require 'stringio' module Calrom module Formatter class Overview < Formatter - def call(calendar, date_range, io = STDOUT) - colnum = (date_range.is_a?(Year) || date_range.each_month.to_a.size > 3) ? 3 : 1 # TODO: expose configuration + def call(calendar, date_range) + colnum = 3 # TODO: expose configuration if date_range.is_a? Year - io.puts center_on(weekdays.size * colnum + 2 * (colnum - 1), date_range.to_s) + puts center_on(weekdays.size * colnum + 2 * (colnum - 1), date_range.to_s) end date_range.each_month.each_slice(colnum) do |months| columns = months.collect do |month| StringIO.new.tap do |io| print_month io, calendar, month, date_range.is_a?(Year) end end - print_columns columns, io + print_columns columns, @io end end private @@ -27,17 +27,22 @@ io.puts center_on weekdays.size, heading io.puts weekdays io.print ' ' * month.first.wday - month.each do |date| - liturgical_day = calendar[date] + calendar.each_day_in_range(month, include_skipped: true) do |liturgical_day| + date = liturgical_day.date - celebration = liturgical_day.celebrations.first + if liturgical_day.skipped? + datestr = ' ' + else + celebration = liturgical_day.celebrations.first - datestr = date.day.to_s.rjust(2) - datestr = highlighter.colour(datestr, celebration.colour) - datestr = highlighter.rank(datestr, celebration.rank) + datestr = date.day.to_s.rjust(2) + datestr = highlighter.colour(datestr, celebration.colour) + datestr = highlighter.rank(datestr, celebration.rank) + end + if date == today datestr = highlighter.today datestr end io.print datestr if date.wday == 6