module Timespan::Printer

Public Instance Methods

print_dates() click to toggle source
print_duration() click to toggle source
print_full() click to toggle source
to_s(mode = :full) click to toggle source

locale-dependent terminology %~s, %~m, %~h, %~d and %~w

%td => total days %th => total hours %tm => total minutes %ts => total seconds

# File lib/timespan/printer.rb, line 20
def to_s mode = :full
        meth = "print_#{mode}"
        raise ArgumentError, "Print mode not supported, was: #{mode}" unless respond_to?(meth)
        send(meth)
end
to_str() click to toggle source
# File lib/timespan/printer.rb, line 26
def to_str
        to_s
end

Protected Instance Methods

duration_format() click to toggle source
# File lib/timespan/printer.rb, line 65
def duration_format
        identifiers = []
        identifiers << 'y' if (duration.years > 0)
        identifiers << 'o' if (duration.months > 0)
        identifiers << 'w' if (duration.weeks > 0)
        identifiers << 'd' if (duration.days > 0)
        identifiers << 'h' if (duration.hours > 0)
        identifiers << 'm' if (duration.minutes > 0)
        identifiers << 's' if (duration.seconds > 0)

        identifiers.map {|id| "%#{id} %~#{id}" }.join(' ')
end
i18n_t(label) click to toggle source
# File lib/timespan/printer.rb, line 44
def i18n_t label
        I18n.t(label, :scope => :timespan, :default => label.to_s)
end
print(type) click to toggle source
time_format() click to toggle source
# File lib/timespan/printer.rb, line 61
def time_format
        Timespan.time_format
end
valid_print_type?(type) click to toggle source
# File lib/timespan/printer.rb, line 57
def valid_print_type? type
        %w{start_time end_time}.include? type.to_s
end