Class: PortugueseValidators::PortugueseBiValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PortugueseValidators::PortugueseBiValidator
- Defined in:
- lib/portuguese_validators/bi.rb
Overview
Validates Portuguese BI’s.
A Portuguese BI number is comprised by eight digits. Between that number and the “issue” box, the card also has a small box with a single digit. That’s the control digit. In order to validate a Portuguese BI you have to give the full number (including the control digit).
Constant Summary collapse
- BLACKLIST =
%w(000000000)
Instance Method Summary collapse
-
#is_valid?(number) ⇒ Boolean
Returns true if the number is a valid BI or false otherwise.
-
#validate_each(record, attribute, value) ⇒ Object
:nodoc:.
Instance Method Details
#is_valid?(number) ⇒ Boolean
Returns true if the number is a valid BI or false otherwise.
17 18 19 20 21 22 |
# File 'lib/portuguese_validators/bi.rb', line 17 def is_valid?(number) return false unless number number = number.to_s looks_like_bi?(number) && valid_bi?(number) end |
#validate_each(record, attribute, value) ⇒ Object
:nodoc:
10 11 12 13 14 |
# File 'lib/portuguese_validators/bi.rb', line 10 def validate_each(record, attribute, value) # :nodoc: unless is_valid?(value) record.errors[attribute] << ([:message] || 'is not a valid BI') end end |