Sha256: c052a4d01f18bb783bc3a237b6fe8c18b19155a24cffeb49ebb17b88c0cd4b3c

Contents?: true

Size: 429 Bytes

Versions: 1

Compression:

Stored size: 429 Bytes

Contents

class IntegerFormatValidator < ActiveModel::EachValidator # :nodoc:
  def validate_each(record, attribute, value)
    Integer(value)
  rescue ArgumentError
    integer = value.to_i
    return if integer == value.to_f && integer != 0
    add_error(record, attribute)
  rescue TypeError
    add_error(record, attribute)
  end

  def add_error(record, attribute)
    record.errors.add(attribute, 'is not a Integer format')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_row_model-1.0.0.beta2 lib/csv_row_model/validators/integer_format_validator.rb