Class: BankTools::SE::Bankgiro
- Inherits:
-
Object
- Object
- BankTools::SE::Bankgiro
- Defined in:
- lib/banktools-se/bankgiro.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #errors ⇒ Object
- #fundraising? ⇒ Boolean
-
#initialize(number) ⇒ Bankgiro
constructor
A new instance of Bankgiro.
- #normalize ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(number) ⇒ Bankgiro
Returns a new instance of Bankgiro.
7 8 9 |
# File 'lib/banktools-se/bankgiro.rb', line 7 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/banktools-se/bankgiro.rb', line 5 def number @number end |
Instance Method Details
#errors ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/banktools-se/bankgiro.rb', line 15 def errors errors = [] errors << Errors::TOO_SHORT if digits.length < 7 errors << Errors::TOO_LONG if digits.length > 8 errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/) errors << Errors::BAD_CHECKSUM unless Utils.valid_luhn?(number) errors end |
#fundraising? ⇒ Boolean
34 35 36 |
# File 'lib/banktools-se/bankgiro.rb', line 34 def fundraising? valid? && digits.match(/\A90[0-4]/) end |
#normalize ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/banktools-se/bankgiro.rb', line 26 def normalize if valid? digits.split(/(\d{4})$/).join("-") else number end end |
#valid? ⇒ Boolean
11 12 13 |
# File 'lib/banktools-se/bankgiro.rb', line 11 def valid? errors.empty? end |