Class: BankTools::SE::Bankgiro

Inherits:
Object
  • Object
show all
Defined in:
lib/banktools-se/bankgiro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#numberObject (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

#errorsObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/banktools-se/bankgiro.rb', line 34

def fundraising?
  valid? && digits.match(/\A90[0-4]/)
end

#normalizeObject



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

Returns:

  • (Boolean)


11
12
13
# File 'lib/banktools-se/bankgiro.rb', line 11

def valid?
  errors.empty?
end