Class: BankAccountTools::BIC
- Inherits:
-
Object
- Object
- BankAccountTools::BIC
- Defined in:
- lib/bank_account_tools/bic.rb
Constant Summary collapse
- REGEX =
/^([A-Z]{4})([A-Z]{2})([A-Z0-9]{2})([A-Z0-9]{3})?$/.freeze
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_formatted_str ⇒ Object
- #to_s(formatted = false) ⇒ Object
- #valid? ⇒ Boolean
- #valid_branch_code? ⇒ Boolean
- #valid_format? ⇒ Boolean
- #valid_location_code? ⇒ Boolean
Constructor Details
#initialize(code) ⇒ BIC
Returns a new instance of BIC.
11 12 13 |
# File 'lib/bank_account_tools/bic.rb', line 11 def initialize(code) @code = code.to_s.gsub(/\s+/, '').upcase end |
Class Method Details
.valid?(code) ⇒ Boolean
7 8 9 |
# File 'lib/bank_account_tools/bic.rb', line 7 def self.valid?(code) new(code).valid? end |
Instance Method Details
#bank_code ⇒ Object
15 16 17 |
# File 'lib/bank_account_tools/bic.rb', line 15 def bank_code @code[0..3] end |
#branch_code ⇒ Object
27 28 29 |
# File 'lib/bank_account_tools/bic.rb', line 27 def branch_code @code[8..10] end |
#country_code ⇒ Object
19 20 21 |
# File 'lib/bank_account_tools/bic.rb', line 19 def country_code @code[4..5] end |
#location_code ⇒ Object
23 24 25 |
# File 'lib/bank_account_tools/bic.rb', line 23 def location_code @code[6..7] end |
#passive? ⇒ Boolean
43 44 45 |
# File 'lib/bank_account_tools/bic.rb', line 43 def passive? location_code[1] == '1' end |
#reverse_billing? ⇒ Boolean
47 48 49 |
# File 'lib/bank_account_tools/bic.rb', line 47 def reverse_billing? location_code[1] == '2' end |
#test? ⇒ Boolean
39 40 41 |
# File 'lib/bank_account_tools/bic.rb', line 39 def test? location_code[1] == '0' end |
#to_formatted_str ⇒ Object
35 36 37 |
# File 'lib/bank_account_tools/bic.rb', line 35 def to_formatted_str "#{bank_code} #{country_code} #{location_code} #{branch_code}".strip end |
#to_s(formatted = false) ⇒ Object
31 32 33 |
# File 'lib/bank_account_tools/bic.rb', line 31 def to_s(formatted=false) formatted ? to_formatted_str : @code end |
#valid? ⇒ Boolean
51 52 53 |
# File 'lib/bank_account_tools/bic.rb', line 51 def valid? valid_format? && valid_location_code? && valid_branch_code? end |
#valid_branch_code? ⇒ Boolean
63 64 65 |
# File 'lib/bank_account_tools/bic.rb', line 63 def valid_branch_code? branch_code.empty? || branch_code == 'XXX' || !branch_code.start_with?('X') end |
#valid_format? ⇒ Boolean
55 56 57 |
# File 'lib/bank_account_tools/bic.rb', line 55 def valid_format? !!@code[REGEX] end |
#valid_location_code? ⇒ Boolean
59 60 61 |
# File 'lib/bank_account_tools/bic.rb', line 59 def valid_location_code? !location_code.start_with?('0', '1') && !location_code.end_with?('O') end |