Class: InferModel::Parsers::Time
- Inherits:
-
Object
- Object
- InferModel::Parsers::Time
- Extended by:
- Dry::Initializer, Callable
- Defined in:
- lib/infer_model/parsers/time.rb
Constant Summary collapse
- ACCEPTABLE_TIME_FORMATS =
%w[%T %R].freeze
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/infer_model/parsers/time.rb', line 15 def call raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank return if value.nil? || value.empty? ACCEPTABLE_TIME_FORMATS.each do |format| return Time.strptime(value, format) rescue ArgumentError next end raise Parsers::Error, "'#{value}' is not a Time" end |