Class: TickTock::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/tick-tock/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(duration) ⇒ Formatter

Returns a new instance of Formatter.



6
7
8
# File 'lib/tick-tock/formatter.rb', line 6

def initialize(duration)
  @duration = duration
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



4
5
6
# File 'lib/tick-tock/formatter.rb', line 4

def duration
  @duration
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
# 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