Sha256: 9256b4eef7bc6ed4a328c72c4910ef56c21031108a7defea2983979dc357425b
Contents?: true
Size: 933 Bytes
Versions: 58
Compression:
Stored size: 933 Bytes
Contents
# frozen_string_literal: true require 'active_support/duration' module Krane # This class is a less strict extension of ActiveSupport::Duration::ISO8601Parser. # In addition to full ISO8601 durations, it can parse unprefixed ISO8601 time components (e.g. '1H'). # It is also case-insensitive. # For example, this class considers the values "1H", "1h" and "PT1H" to be valid and equivalent. class DurationParser class ParsingError < ArgumentError; end def initialize(value) @iso8601_str = value.to_s.strip.upcase end def parse! ActiveSupport::Duration.parse("PT#{@iso8601_str}") # By default assume it is just a time component rescue ActiveSupport::Duration::ISO8601Parser::ParsingError begin ActiveSupport::Duration.parse(@iso8601_str) rescue ActiveSupport::Duration::ISO8601Parser::ParsingError => e raise ParsingError, e.message end end end end
Version data entries
58 entries across 58 versions & 3 rubygems