class TickTock::Formatter

Attributes

duration[R]

Public Class Methods

new(duration) click to toggle source
# File lib/tick-tock/formatter.rb, line 6
def initialize(duration)
  @duration = duration
end

Public Instance Methods

to_s() click to toggle source
# File lib/tick-tock/formatter.rb, line 10
def to_s
  "".tap do |s|
    s << " #{duration.years}y" if include_years?
    s << " #{duration.weeks}w" if include_weeks?
    s << " #{duration.days}d" if include_days?
    s << " #{duration.hours}h" if include_hours?
    s << " #{duration.minutes}m" if include_minutes?
    s << " #{duration.seconds}s" if include_seconds?
    s << " #{duration.millis}ms" if include_millis?
    s.lstrip!
  end
end

Private Instance Methods

at_or_beyond?(boundary) click to toggle source
# File lib/tick-tock/formatter.rb, line 53
def at_or_beyond?(boundary)
  @duration.raw_millis >= boundary
end
include_days?() click to toggle source
# File lib/tick-tock/formatter.rb, line 41
def include_days?
  at_or_beyond? TickTock::Duration::MILLIS_IN_DAY
end
include_hours?() click to toggle source
# File lib/tick-tock/formatter.rb, line 37
def include_hours?
  at_or_beyond? TickTock::Duration::MILLIS_IN_HOUR
end
include_millis?() click to toggle source
# File lib/tick-tock/formatter.rb, line 25
def include_millis?
  true
end
include_minutes?() click to toggle source
# File lib/tick-tock/formatter.rb, line 33
def include_minutes?
  at_or_beyond? TickTock::Duration::MILLIS_IN_MINUTE
end
include_seconds?() click to toggle source
# File lib/tick-tock/formatter.rb, line 29
def include_seconds?
  at_or_beyond? TickTock::Duration::MILLIS_IN_SECOND
end
include_weeks?() click to toggle source
# File lib/tick-tock/formatter.rb, line 45
def include_weeks?
  at_or_beyond? TickTock::Duration::MILLIS_IN_WEEK
end
include_years?() click to toggle source
# File lib/tick-tock/formatter.rb, line 49
def include_years?
  at_or_beyond? TickTock::Duration::MILLIS_IN_YEAR
end