Class: TimeBoss::Calendar::Support::Formatter
- Inherits:
-
Object
- Object
- TimeBoss::Calendar::Support::Formatter
- Defined in:
- lib/timeboss/calendar/support/formatter.rb
Overview
The formatter is responsible for the implementation of name formatting for a unit.
Constant Summary collapse
- PERIODS =
Translatable::PERIODS.reverse.map(&:to_sym).drop(1)
Instance Attribute Summary collapse
-
#periods ⇒ Object
readonly
Returns the value of attribute periods.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
-
#initialize(unit, periods) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_s ⇒ Object
Constructor Details
#initialize(unit, periods) ⇒ Formatter
15 16 17 18 19 |
# 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 |
Instance Attribute Details
#periods ⇒ Object (readonly)
Returns the value of attribute periods.
13 14 15 |
# File 'lib/timeboss/calendar/support/formatter.rb', line 13 def periods @periods end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
13 14 15 |
# File 'lib/timeboss/calendar/support/formatter.rb', line 13 def unit @unit end |
Instance Method Details
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# 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 |