module Dry::Types::Coercions

def empty_str?(value)

Returns:
  • (Boolean) -

Parameters:
  • value (String, Object) --
def empty_str?(value)
  EMPTY_STRING.eql?(value)
end

def to_date(input)

Other tags:
    See: Date.parse -

Returns:
  • (Date, Object) -

Parameters:
  • input (#to_str, Object) --
def to_date(input)
  return input unless input.respond_to?(:to_str)
  Date.parse(input)
rescue ArgumentError, RangeError
  input
end

def to_date_time(input)

Other tags:
    See: DateTime.parse -

Returns:
  • (DateTime, Object) -

Parameters:
  • input (#to_str, Object) --
def to_date_time(input)
  return input unless input.respond_to?(:to_str)
  DateTime.parse(input)
rescue ArgumentError
  input
end

def to_nil(input)

Returns:
  • (Object) - otherwise the input object is returned
  • (nil) - if the input is an empty string

Parameters:
  • input (String, Object) --
def to_nil(input)
  input unless empty_str?(input)
end

def to_time(input)

Other tags:
    See: Time.parse -

Returns:
  • (Time, Object) -

Parameters:
  • input (#to_str, Object) --
def to_time(input)
  return input unless input.respond_to?(:to_str)
  Time.parse(input)
rescue ArgumentError
  input
end