Module: HandBrake::DurationAsSeconds

Included in:
Chapter, Title
Defined in:
lib/handbrake/disc.rb

Overview

Provides a #seconds method for an object which has a duration property whose value is a string of the format "hh:mm:ss"

Instance Method Summary collapse

Instance Method Details

#secondsFixnum

The number of seconds described by the duration. E.g., if the duration were "1:02:42", this method would return 3762.

Returns:

  • (Fixnum)


119
120
121
122
# File 'lib/handbrake/disc.rb', line 119

def seconds
  @seconds ||= duration.split(':').collect(&:to_i).reverse.
    inject([1, 0]) { |(m, sum), i| [m * 60, sum + i * m] }.last
end