class TimeBoss::Calendar::Support::Formatter

The formatter is responsible for the implementation of name formatting for a unit.

Constants

PERIODS

Attributes

periods[R]
unit[R]

Public Class Methods

new(unit, periods) click to toggle source
# File lib/timeboss/calendar/support/formatter.rb, line 15
def initialize(unit, periods)
  @unit = unit
  @periods = PERIODS & periods.map(&:to_sym).push(unit.class.type.to_sym)
  @periods -= [:week] unless unit.calendar.supports_weeks?
end

Public Instance Methods

to_s() click to toggle source
# File lib/timeboss/calendar/support/formatter.rb, line 21
def to_s
  base, text = "year", unit.year.name
  periods.each do |period|
    (sub = unit.public_send(period)) || break
    index = sub.public_send("in_#{base}")
    text += "#{period[0].upcase}#{index}"
    base = period
  end
  text
end