Module: VkMusic::Utility::DurationParser
- Defined in:
- lib/vk_music/utility/duration_parser.rb
Overview
Turn human readable track length to its size in seconds
Class Method Summary collapse
-
.call(str) ⇒ Integer
Amount of seconds.
Class Method Details
.call(str) ⇒ Integer
Returns amount of seconds.
9 10 11 12 13 14 15 16 |
# File 'lib/vk_music/utility/duration_parser.rb', line 9 def self.call(str) str .scan(/\d+/) .map { |i| Integer(i, 10) } .reverse .each_with_index .reduce(0) { |acc, (count, position)| acc + (count * (60**position)) } end |