module Timespan::Printer
Public Instance Methods
print_dates()
click to toggle source
# File lib/timespan/printer.rb, line 30 def print_dates "#{i18n_t 'from'} #{print :start_time} #{i18n_t 'to'} #{print :end_time}" end
print_duration()
click to toggle source
# File lib/timespan/printer.rb, line 34 def print_duration print :duration end
print_full()
click to toggle source
# File lib/timespan/printer.rb, line 38 def print_full [print_dates, i18n_t('lasting'), print_duration].join(' ') end
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
# File lib/timespan/printer.rb, line 48 def print type return duration.format(duration_format) if type == :duration raise ArgumentError, "Not a valid print type, was: #{type}" unless valid_print_type? type return "ASAP" if type == :start_time && asap? send(type).strftime(time_format) end
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