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.



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

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

Class Method Details

.valid?(code) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#bank_codeObject



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

def bank_code
  @code[0..3]
end

#branch_codeObject



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

def branch_code
  @code[8..10]
end

#country_codeObject



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

def country_code
  @code[4..5]
end

#location_codeObject



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

def location_code
  @code[6..7]
end

#passive?Boolean

Returns:

  • (Boolean)


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

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

#reverse_billing?Boolean

Returns:

  • (Boolean)


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

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

#test?Boolean

Returns:

  • (Boolean)


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

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

#to_s(formatted = false) ⇒ Object



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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

#valid_branch_code?Boolean

Returns:

  • (Boolean)


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

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

#valid_format?Boolean

Returns:

  • (Boolean)


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

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

#valid_length?Boolean

Returns:

  • (Boolean)


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

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

#valid_location_code?Boolean

Returns:

  • (Boolean)


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

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