Class: BankTools::Global::IBAN
- Inherits:
-
Object
- Object
- BankTools::Global::IBAN
- Defined in:
- lib/banktools/global/iban.rb
Constant Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(raw) ⇒ IBAN
constructor
A new instance of IBAN.
- #normalize ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw) ⇒ IBAN
Returns a new instance of IBAN.
9 10 11 |
# File 'lib/banktools/global/iban.rb', line 9 def initialize(raw) @pre_normalized = raw.to_s.gsub(/\s/, "").upcase end |
Instance Method Details
#errors ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/banktools/global/iban.rb', line 17 def errors rule = rules[country_code] return [ E::UNKNOWN_COUNTRY ] unless rule length = rule.fetch("length") return [ E::WRONG_LENGTH ] unless @pre_normalized.length == length re = rule.fetch("bban_pattern") return [ E::BAD_FORMAT ] unless bban.match?(re) return [ E::BAD_CHECKSUM ] unless good_checksum? [] end |
#normalize ⇒ Object
32 33 34 |
# File 'lib/banktools/global/iban.rb', line 32 def normalize @pre_normalized.gsub(/.{4}/, '\0 ').strip end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/banktools/global/iban.rb', line 13 def valid? errors.empty? end |