Skip to content

Instantly share code, notes, and snippets.

/pry_gist.rb Secret

Created September 13, 2013 00:46
Show Gist options
  • Save anonymous/f622df51ed55679f03af to your computer and use it in GitHub Desktop.
Save anonymous/f622df51ed55679f03af to your computer and use it in GitHub Desktop.
class TimeDuration
def initialize(duration)
result = duration.match(/^(\d+)\s+(\w+)$/)
durations = { "day" => 60*60*24, "days" => 60*60*24, "min" => 60, "minute" => 60, "minutes" => 60, "hour" => 60*60, "hours" => 60*60, "week" => 60*60*24*7, "weeks" => 60*60*24*7, "year" => 60*60*24*365, "years" => 60*60*24*365 }
@duration = result[1].to_i * durations[result[2]]
end
def +(time_stamp)
time_stamp + @duration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment