module VkMusic::Utility::DurationParser
Turn human readable track length to its size in seconds
Public Class Methods
call(str)
click to toggle source
@param str [String] string in format “HH:MM:SS” or something alike (/d+
Regex selector is used) @return [Integer] amount of seconds
# File lib/vk_music/utility/duration_parser.rb, line 9 def self.call(str) str.scan(/\d+/) .map(&:to_i) .reverse .each_with_index.reduce(0) { |acc, (count, position)| acc + count * 60**position } end