module Expire::FromRangeValue
Provide a pseudo constructor for rules that require a time range
Constants
- FROM_VALUE_REGEX
Public Instance Methods
from_value(string, **args)
click to toggle source
# File lib/expire/from_range_value.rb, line 16 def from_value(string, **args) # return new(args.merge({ amount: 0, unit: nil })) if string.none? return new(**args.merge(amount: 0, unit: nil)) if string.none? stripped_down = string.strip.downcase match = stripped_down.match FROM_VALUE_REGEX raise ArgumentError, "#{string} is not a valid range value" unless match amount = Integer(match[1]) unit = match[5] new(**args.merge(amount: amount, unit: unit)) end