Class: PortugueseValidators::PortugueseNibValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PortugueseValidators::PortugueseNibValidator
- Defined in:
- lib/portuguese_validators/nib.rb
Overview
Validates Portuguese bank numbers (NIB).
The number is always composed by 21 where the last two form the control number.
Instance Method Summary collapse
Instance Method Details
#is_valid?(number) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/portuguese_validators/nib.rb', line 12 def is_valid?(number) return false unless number number = sprintf("%021o", number) if number.kind_of?(Integer) looks_like_nib?(number) && valid_nib?(number) end |
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 |
# File 'lib/portuguese_validators/nib.rb', line 6 def validate_each(record, attribute, value) unless is_valid?(value) record.errors[attribute] << ([:message] || 'is not a valid NIB') end end |