Sha256: 3ab89348ea006b5460db8fa7ccf36eea7ef29923b8ebd31a949c3ba935605c34
Contents?: true
Size: 765 Bytes
Versions: 6
Compression:
Stored size: 765 Bytes
Contents
# frozen_string_literal: true module Expire # Provide a pseudo constructor for rules that require a time range module FromRangeValue using RefineAllAndNone FROM_VALUE_REGEX = / \A (([0-9](_[0-9]+){0,})+) (\s+|\.) (hour|day|week|month|year)s? \z /x 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 end end
Version data entries
6 entries across 6 versions & 1 rubygems