Class: BankTools::SE::Plusgiro
- Inherits:
-
Object
- Object
- BankTools::SE::Plusgiro
- Defined in:
- lib/banktools-se/plusgiro.rb
Constant Summary collapse
- MAX_LENGTH =
Could sadly not find anything more authoritative than
http://pellesoft.se/communicate/forum/view.aspx?msgid=267449&forumid=63&sum=0 https://www.nordea.se/foretag/kundservice/fragor-och-svar-konton.html#faq=Kontouppgifter+432454 10- MIN_LENGTH =
2
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #errors ⇒ Object
- #fundraising? ⇒ Boolean
-
#initialize(number) ⇒ Plusgiro
constructor
A new instance of Plusgiro.
- #normalize ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(number) ⇒ Plusgiro
Returns a new instance of Plusgiro.
13 14 15 |
# File 'lib/banktools-se/plusgiro.rb', line 13 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
11 12 13 |
# File 'lib/banktools-se/plusgiro.rb', line 11 def number @number end |
Instance Method Details
#errors ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/banktools-se/plusgiro.rb', line 21 def errors errors = [] errors << Errors::TOO_SHORT if digits.length < MIN_LENGTH errors << Errors::TOO_LONG if digits.length > MAX_LENGTH errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/) errors << Errors::BAD_CHECKSUM unless Utils.valid_luhn?(number) errors end |
#fundraising? ⇒ Boolean
44 45 46 |
# File 'lib/banktools-se/plusgiro.rb', line 44 def fundraising? valid? && digits.match(/\A90\d{5}$/) end |
#normalize ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/banktools-se/plusgiro.rb', line 32 def normalize if valid? pre, pairs, post = digits.split(/(\d{2}*)(\d)$/) pairs = pairs.split(/(\d\d)/).reject(&:empty?) [ pre, pairs.join(" "), "-", post ].join else number end end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/banktools-se/plusgiro.rb', line 17 def valid? errors.empty? end |