Class: Bank::BIC

Inherits:
Object
  • Object
show all
Defined in:
lib/bank/bic.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ BIC

Returns a new instance of BIC.



10
11
12
# File 'lib/bank/bic.rb', line 10

def initialize(code)
  @code = code.to_s.strip.gsub(/\s+/, '').upcase
end

Class Method Details

.valid?(code) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/bank/bic.rb', line 6

def self.valid?(code)
  new(code).valid?
end

Instance Method Details

#bank_codeObject



14
15
16
# File 'lib/bank/bic.rb', line 14

def bank_code
  @code[0..3]
end

#branch_codeObject



26
27
28
# File 'lib/bank/bic.rb', line 26

def branch_code
  @code[8..10]
end

#country_codeObject



18
19
20
# File 'lib/bank/bic.rb', line 18

def country_code
  @code[4..5]
end

#location_codeObject



22
23
24
# File 'lib/bank/bic.rb', line 22

def location_code
  @code[6..7]
end

#passive?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/bank/bic.rb', line 38

def passive?
  location_code[1] == '1'
end

#reverse_billing?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/bank/bic.rb', line 42

def reverse_billing?
  location_code[1] == '2'
end

#test?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bank/bic.rb', line 34

def test?
  location_code[1] == '0'
end

#to_s(formatted = false) ⇒ Object



30
31
32
# File 'lib/bank/bic.rb', line 30

def to_s(formatted=false)
  formatted ? "#{bank_code} #{country_code} #{location_code} #{branch_code}".strip : @code
end

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/bank/bic.rb', line 46

def valid?
  valid_length? && valid_format? && valid_location_code? && valid_branch_code?
end

#valid_branch_code?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/bank/bic.rb', line 62

def valid_branch_code?
  branch_code.nil? || !(branch_code[0] == 'X' && branch_code != 'XXX')
end

#valid_format?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/bank/bic.rb', line 54

def valid_format?
  @code =~ /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/
end

#valid_length?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bank/bic.rb', line 50

def valid_length?
  @code.length == 8 || @code.length == 11
end

#valid_location_code?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/bank/bic.rb', line 58

def valid_location_code?
  location_code[0] != '0' && location_code[0] != '1' && location_code[1] != 'O'
end