ibanizator 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ class BankNotFoundError < Exception
2
+ end
@@ -0,0 +1,2 @@
1
+ class InvalidBankCodeError < Exception
2
+ end
@@ -1,10 +1,13 @@
1
1
  require 'sqlite3'
2
- require 'ruby-debug'
2
+ require_relative '../errors/invalid_bank_code_error'
3
+ require_relative '../errors/bank_not_found_error'
3
4
 
4
5
  module SwiftBic
5
6
  class BankDb
6
- def initialize bank_number
7
- @bank_data = load_table_row bank_number
7
+ def initialize bank_code
8
+ validate_bank_code bank_code
9
+ @bank_data = load_table_row bank_code
10
+ raise BankNotFoundError unless @bank_data
8
11
  end
9
12
 
10
13
  def bank_name
@@ -15,13 +18,20 @@ module SwiftBic
15
18
  @bank_data[2]
16
19
  end
17
20
 
21
+ def validate_bank_code bank_code
22
+ if bank_code.length == 8
23
+ return true
24
+ else
25
+ raise InvalidBankCodeError
26
+ end
27
+ end
18
28
 
19
29
  private
20
30
 
21
- def load_table_row bank_number
31
+ def load_table_row bank_code
22
32
  begin
23
33
  db = SQLite3::Database.open(File.expand_path("../../../db/blz.db", __FILE__))
24
- row = db.execute("SELECT * FROM blz WHERE blz = '#{bank_number}'")
34
+ row = db.execute("SELECT * FROM blz WHERE blz = '#{bank_code}'")
25
35
  rescue SQLite3::Exception => e
26
36
  throw e
27
37
  ensure
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibanizator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
@@ -46,6 +46,8 @@ files:
46
46
  - lib/iban/lengths.rb
47
47
  - lib/swift_bic/bank_db.rb
48
48
  - db/blz.db
49
+ - lib/errors/bank_not_found_error.rb
50
+ - lib/errors/invalid_bank_code_error.rb
49
51
  homepage: https://github.com/softwareinmotion/ibanizator
50
52
  licenses: []
51
53
  post_install_message:
@@ -69,5 +71,5 @@ rubyforge_project:
69
71
  rubygems_version: 1.8.24
70
72
  signing_key:
71
73
  specification_version: 3
72
- summary: An IBAN generator/validator for german accounts.
74
+ summary: An IBAN generator/validator and BIC generator for german accounts.
73
75
  test_files: []