Sha256: 1d209f7a511299b573dc43e7aaaaf5852bbf73b5fc5c8cc3b7800e9ff90a7068

Contents?: true

Size: 476 Bytes

Versions: 2

Compression:

Stored size: 476 Bytes

Contents

class CurrencyValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    unless valid?(value, options)
      record.errors[attribute] << (options[:message] || I18n.t('errors.messages.currency'))
    end
  end

  private

  def valid_format?(value, options)
    if options[:strict]
      value =~ /^\d+(\.\d{2})$/
    else
      value =~ /^\d*+(\.\d{1,2})$/
    end
  end

  def valid?(value, options)
    valid_format?(value, options)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-3.0.1 lib/flash_validators/validators/currency_validator.rb
flash_validators-3.0.0 lib/flash_validators/validators/currency_validator.rb