Class: BankTools::SE::Plusgiro
- Inherits:
-
Object
- Object
- BankTools::SE::Plusgiro
- Defined in:
- lib/banktools-se/plusgiro.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Could sadly not find anything more authoritative than pellesoft.se/communicate/forum/view.aspx?msgid=267449&forumid=63&sum=0.
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.
10 11 12 |
# File 'lib/banktools-se/plusgiro.rb', line 10 def initialize(number) @number = number end |
Instance Attribute Details
#number ⇒ Object (readonly)
Could sadly not find anything more authoritative than
http://pellesoft.se/communicate/forum/view.aspx?msgid=267449&forumid=63&sum=0
8 9 10 |
# File 'lib/banktools-se/plusgiro.rb', line 8 def number @number end |
Instance Method Details
#errors ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/banktools-se/plusgiro.rb', line 18 def errors errors = [] errors << Errors::TOO_SHORT if digits.length < 2 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
41 42 43 |
# File 'lib/banktools-se/plusgiro.rb', line 41 def fundraising? valid? && digits.match(/\A90\d{5}$/) end |
#normalize ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/banktools-se/plusgiro.rb', line 29 def normalize if valid? pre, pairs, post = digits.split(/(\d{2}*)(\d)$/) pairs = pairs.split(/(\d\d)/).reject { |x| x.empty? } [ pre, pairs.join(" "), "-", post ].join else number end end |
#valid? ⇒ Boolean
14 15 16 |
# File 'lib/banktools-se/plusgiro.rb', line 14 def valid? errors.empty? end |