Sha256: 268d06aef45558fa6300d7f90ed997c9fcf9ce2159190d99c882d9d3c5dcd451
Contents?: true
Size: 906 Bytes
Versions: 10
Compression:
Stored size: 906 Bytes
Contents
# frozen_string_literal: true require_relative './translatable' module TimeBoss class Calendar module Support private # The formatter is responsible for the implementation of name formatting for a unit. class Formatter PERIODS = Translatable::PERIODS.reverse.map(&:to_sym).drop(1) attr_reader :unit, :periods 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 def to_s base, text = 'year', unit.year.name periods.each do |period| sub = unit.send(period) or break index = sub.send("in_#{base}") text += "#{period[0].upcase}#{index}" base = period end text end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems