Class: Bank::BIC
- Inherits:
-
Object
- Object
- Bank::BIC
- Defined in:
- lib/bank/bic.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bank_code ⇒ Object
- #branch_code ⇒ Object
- #country_code ⇒ Object
-
#initialize(code) ⇒ BIC
constructor
A new instance of BIC.
- #location_code ⇒ Object
- #passive? ⇒ Boolean
- #reverse_billing? ⇒ Boolean
- #test? ⇒ Boolean
- #to_s(formatted = false) ⇒ Object
- #valid? ⇒ Boolean
- #valid_branch_code? ⇒ Boolean
- #valid_format? ⇒ Boolean
- #valid_length? ⇒ Boolean
- #valid_location_code? ⇒ Boolean
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
6 7 8 |
# File 'lib/bank/bic.rb', line 6 def self.valid?(code) new(code).valid? end |
Instance Method Details
#bank_code ⇒ Object
14 15 16 |
# File 'lib/bank/bic.rb', line 14 def bank_code @code[0..3] end |
#branch_code ⇒ Object
26 27 28 |
# File 'lib/bank/bic.rb', line 26 def branch_code @code[8..10] end |
#country_code ⇒ Object
18 19 20 |
# File 'lib/bank/bic.rb', line 18 def country_code @code[4..5] end |
#location_code ⇒ Object
22 23 24 |
# File 'lib/bank/bic.rb', line 22 def location_code @code[6..7] end |
#passive? ⇒ Boolean
38 39 40 |
# File 'lib/bank/bic.rb', line 38 def passive? location_code[1] == '1' end |
#reverse_billing? ⇒ Boolean
42 43 44 |
# File 'lib/bank/bic.rb', line 42 def reverse_billing? location_code[1] == '2' end |
#test? ⇒ 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
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
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
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
50 51 52 |
# File 'lib/bank/bic.rb', line 50 def valid_length? @code.length == 8 || @code.length == 11 end |
#valid_location_code? ⇒ 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 |