Sha256: 900063c635f22e8b1b41031ca7e9ff2c8d5d935c363c4d67549800bb2c1d72fb
Contents?: true
Size: 742 Bytes
Versions: 6
Compression:
Stored size: 742 Bytes
Contents
# frozen_string_literal: true require_relative './shiftable' module TimeBoss class Calendar module Support private class Formatter PERIODS = Shiftable::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) 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
6 entries across 6 versions & 1 rubygems