Class: AudioPlayback::Position

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/audio-playback/position.rb

Overview

A time position in a sound

Defined Under Namespace

Classes: InvalidTime

Constant Summary collapse

UNITS =
[
  1, # second
  60, # minute
  3600 # hour
].freeze
FORMAT =

Time format like (hh:)(mm:)ss(.ss)

/((\d+\:)(\d{2}\:)|(\d{2}\:))?\d{1,2}(\.\d+)?/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds_or_time) ⇒ Position

Returns a new instance of Position.

Parameters:

  • seconds_or_time (Numeric, String)

    Time as (hh:)(mm:)ss(.ss)



25
26
27
28
29
# File 'lib/audio-playback/position.rb', line 25

def initialize(seconds_or_time)
  seconds_or_time = seconds_or_time.to_s
  validate_time(seconds_or_time)
  populate(seconds_or_time)
end

Instance Attribute Details

#secondsObject (readonly) Also known as: to_seconds

Returns the value of attribute seconds.



20
21
22
# File 'lib/audio-playback/position.rb', line 20

def seconds
  @seconds
end

Instance Method Details

#*(another) ⇒ Float

Multiply the seconds value of this Position by the given value

Parameters:

Returns:

  • (Float)


34
35
36
# File 'lib/audio-playback/position.rb', line 34

def *(another)
  @seconds * another.to_f
end

#+(another) ⇒ Float

Add the seconds value of this Position to the given value

Parameters:

Returns:

  • (Float)


41
42
43
# File 'lib/audio-playback/position.rb', line 41

def +(another)
  @seconds + another.to_f
end