9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/crawler/cinema/duration.rb', line 9
def parse(str)
duration = 0
duration_matches = str.match(/^((?<hours>\d+)(h|hours?))?\s*((?<minutes>\d+)(m|minutes?|mins?))?\s*((?<seconds>\d+)(s|seconds?|secs?))?$/i)
if duration_matches
duration += duration_matches[:hours].to_i * SECONDS_PER_HOUR if duration_matches[:hours]
duration += duration_matches[:minutes].to_i * SECONDS_PER_MINUTE if duration_matches[:minutes]
duration += duration_matches[:seconds].to_i if duration_matches[:seconds]
end
duration
end
|