evazion
2019-09-08 15:32:31 -05:00
parent 22fd90eee9
commit 24202d51f0
4 changed files with 42 additions and 25 deletions

View File

@@ -0,0 +1,27 @@
module DurationParser
def self.parse(string)
string =~ /(\d+)(s(econds?)?|mi(nutes?)?|h(ours?)?|d(ays?)?|w(eeks?)?|mo(nths?)?|y(ears?)?)?/i
size = $1.to_i
unit = $2
case unit
when /^s/i
size.seconds
when /^mi/i
size.minutes
when /^h/i
size.hours
when /^d/i
size.days
when /^w/i
size.weeks
when /^mo/i
size.months
when /^y/i
size.years
else
size.seconds
end
end
end