class Calrom::Formatter::Overview

Public Instance Methods

call(calendar, date_range, io = STDOUT) click to toggle source
# File lib/calrom/formatter/overview.rb, line 7
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
  if date_range.is_a? Year
    io.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
  end
end

Private Instance Methods

center_on(line_length, content) click to toggle source

centers given string on a given line length

# File lib/calrom/formatter/overview.rb, line 65
def center_on(line_length, content)
  (' ' * (line_length / 2 - content.size / 2)) +
    content
end
colour_aware_size(str) click to toggle source

String length ignoring colour codes

# File lib/calrom/formatter/overview.rb, line 94
def colour_aware_size(str)
  ColorizedString.new(str).uncolorize.size
end
print_columns(columns, io) click to toggle source
print_month(io, calendar, month, year_in_heading) click to toggle source
weekdays() click to toggle source

localizable 2-character weekday shortcuts

# File lib/calrom/formatter/overview.rb, line 53
def weekdays
  @weekdays ||=
    begin
      sunday = Date.new 1987, 10, 25
      sunday
        .upto(sunday + 6)
        .collect {|d| d.strftime('%a')[0..1] }
        .join(' ')
    end
end