Sha256: 031ec4f50efa382c579c10852d0084aa4f3050b7d2f3fed1007bca583dc95688

Contents?: true

Size: 465 Bytes

Versions: 17

Compression:

Stored size: 465 Bytes

Contents

class BooleanFormatValidator < ActiveModel::EachValidator # :nodoc:
  # inspired by https://github.com/MrJoy/to_bool/blob/5c9ed38e47c638725e33530ea1a8aec96281af20/lib/to_bool.rb#L23
  FALSE_BOOLEAN_REGEX = /^(false|f|no|n|0|)$/i
  TRUE_BOOLEAN_REGEX = /^(true|t|yes|y|1)$/i

  def validate_each(record, attribute, value)
    return if value =~ FALSE_BOOLEAN_REGEX || value =~ TRUE_BOOLEAN_REGEX

    record.errors.add(attribute, 'is not a Boolean format')
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
csv_row_model-1.0.0.beta1 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.4.1 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.4.0 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.10 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.9 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.8 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.7 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.6 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.5 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.4 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.3 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.2 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.1 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.3.0 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.2.1 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.1.1 lib/csv_row_model/validators/boolean_format.rb
csv_row_model-0.1.0 lib/csv_row_model/validators/boolean_format.rb