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.
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
5 6 7 |
# File 'lib/bank/bic.rb', line 5 def self.valid?(code) new(code).valid? end |
Instance Method Details
#bank_code ⇒ Object
13 14 15 |
# File 'lib/bank/bic.rb', line 13 def bank_code @code[0..3] end |
#branch_code ⇒ Object
25 26 27 |
# File 'lib/bank/bic.rb', line 25 def branch_code @code[8..10] end |
#country_code ⇒ Object
17 18 19 |
# File 'lib/bank/bic.rb', line 17 def country_code @code[4..5] end |
#location_code ⇒ Object
21 22 23 |
# File 'lib/bank/bic.rb', line 21 def location_code @code[6..7] end |
#passive? ⇒ Boolean
37 38 39 |
# File 'lib/bank/bic.rb', line 37 def passive? location_code[1] == '1' end |
#reverse_billing? ⇒ Boolean
41 42 43 |
# File 'lib/bank/bic.rb', line 41 def reverse_billing? location_code[1] == '2' end |
#test? ⇒ 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
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
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
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
49 50 51 |
# File 'lib/bank/bic.rb', line 49 def valid_length? @code.length == 8 || @code.length == 11 end |
#valid_location_code? ⇒ 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 |