Class: Temporalize::Seconds

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalize/seconds.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds, format_string = Formats::DEFAULT, milliseconds = nil) ⇒ Seconds



7
8
9
10
11
# File 'lib/temporalize/seconds.rb', line 7

def initialize(seconds, format_string = Formats::DEFAULT, milliseconds = nil)
  @seconds = seconds.to_i.abs  # Handle negative values by taking absolute value
  @format_string = resolve_format(format_string)
  @milliseconds = milliseconds
end

Instance Attribute Details

#format_stringObject (readonly)

Returns the value of attribute format_string.



5
6
7
# File 'lib/temporalize/seconds.rb', line 5

def format_string
  @format_string
end

#millisecondsObject (readonly)

Returns the value of attribute milliseconds.



5
6
7
# File 'lib/temporalize/seconds.rb', line 5

def milliseconds
  @milliseconds
end

#secondsObject (readonly)

Returns the value of attribute seconds.



5
6
7
# File 'lib/temporalize/seconds.rb', line 5

def seconds
  @seconds
end

Instance Method Details

#to_s(override_format = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/temporalize/seconds.rb', line 13

def to_s(override_format = nil)
  format_to_use = override_format ? resolve_format(override_format) : @format_string

  case format_to_use
  when :natural
    to_natural
  when :minutes_seconds
    format_minutes_seconds
  else
    format_duration(format_to_use)
  end
end