Class: PagseguroDecimalValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/pagseguro_decimal_validator.rb

Instance Method Summary collapse

Instance Method Details

#error_messageObject



8
9
10
# File 'lib/pagseguro_decimal_validator.rb', line 8

def error_message
  " must be a decimal and have 2 digits after the dot"
end

#validate_each(object, attribute, value) ⇒ Object



2
3
4
5
6
# File 'lib/pagseguro_decimal_validator.rb', line 2

def validate_each(object, attribute, value)
  unless value.nil? || value =~ /\A\d+\.\d{2}\z/
    object.errors.add(attribute, error_message)
  end
end