Module: DurationExtensions::ClassMethods
- Defined in:
- lib/duration_extensions.rb
Instance Method Summary collapse
Instance Method Details
#parse(timecode) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/duration_extensions.rb', line 14 def parse(timecode) return timecode if timecode.is_a? Numeric tokens = timecode.split(/\D+/).map(&:to_i).reverse multipliers = [:seconds, :minutes, :hours, :days] parts = [] seconds = tokens.inject(0) {|total, token| unit = multipliers.shift parts << [unit, token] total += token.send(unit) } new(seconds, parts) end |