Class: BankTools::DE::BLZ

Inherits:
Object
  • Object
show all
Defined in:
lib/banktools-de/blz.rb

Constant Summary collapse

LENGTH =
8
BLZ_TO_BANK_NAME_PATH =
File.join(BankTools::DE.data_dir, "blz_to_name.yml")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blz_to_bank_nameObject



20
21
22
# File 'lib/banktools-de/blz.rb', line 20

def self.blz_to_bank_name
  @blz_to_bank_name ||= YAML.load_file(BLZ_TO_BANK_NAME_PATH).fetch(:data)
end

Instance Method Details

#bank_nameObject



44
45
46
# File 'lib/banktools-de/blz.rb', line 44

def bank_name
  blz_to_bank_name.fetch(compacted_value, nil)
end

#errorsObject



36
37
38
39
40
41
42
# File 'lib/banktools-de/blz.rb', line 36

def errors
  errors = []
  errors << Errors::TOO_SHORT if compacted_value.length < LENGTH
  errors << Errors::TOO_LONG if compacted_value.length > LENGTH
  errors << Errors::INVALID_CHARACTERS if compacted_value.match(/\D/)
  errors
end

#normalizeObject



24
25
26
27
28
29
30
# File 'lib/banktools-de/blz.rb', line 24

def normalize
  if compacted_value.match(/\A(\d{3})(\d{3})(\d{2})\z/)
    "#$1 #$2 #$3"
  else
    original_value
  end
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/banktools-de/blz.rb', line 32

def valid?
  errors.empty?
end