module RequestParamsValidation::Params::Types::Conversions

Public Instance Methods

convert_to_boolean(value) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 23
def convert_to_boolean(value)
  Params::BOOLEAN_TRUE_VALUES.include?(value)
end
convert_to_date(value, format) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 27
def convert_to_date(value, format)
  format = format || RequestParamsValidation.formats.date

  format ? Date.strptime(value, format) : Date.parse(value)
end
convert_to_datetime(value, format) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 33
def convert_to_datetime(value, format)
  format = format || RequestParamsValidation.formats.datetime

  format ? DateTime.strptime(value, format) : DateTime.parse(value)
end
convert_to_decimal(value, precision) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 13
def convert_to_decimal(value, precision)
  precision = precision || RequestParamsValidation.formats.decimal_precision

  value = Float(value)

  value = value.round(precision) if precision

  value
end
convert_to_integer(value) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 9
def convert_to_integer(value)
  Integer(value)
end
convert_to_string(value) click to toggle source
# File lib/request_params_validation/params/types/conversions.rb, line 5
def convert_to_string(value)
  String(value)
end