ibanizator 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ibanizator.rb CHANGED
@@ -8,7 +8,7 @@ class Ibanizator
8
8
 
9
9
  # Fill account number to 10 digits
10
10
  while options[:account_number].size < 10 do
11
- options[:account_number].insert(0, '0')
11
+ options[:account_number] = options[:account_number].rjust(10, '0')
12
12
  end
13
13
 
14
14
  country_code_num = character_to_digit options[:country_code].to_s
@@ -34,7 +34,7 @@ class Ibanizator
34
34
  end
35
35
 
36
36
  def character_to_digit char
37
- char.upcase!.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
37
+ char.upcase.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
38
38
  end
39
39
 
40
40
  def calculate_checksum bank_code, account_number, country_code_num
@@ -1,21 +1,30 @@
1
- require 'sqlite3'
2
1
  require_relative '../errors/invalid_bank_code_error'
3
2
  require_relative '../errors/bank_not_found_error'
4
3
 
5
4
  module SwiftBic
6
5
  class BankDb
6
+
7
+ BANKS = {}.tap do |banks|
8
+ File.open(File.expand_path("../../../db/blz.txt", __FILE__), 'r').each_line do |line|
9
+ code, _, _, _, _, name, _, bic = line.unpack 'A8A1A58A5A35A27A5A11'
10
+ next if bic.empty?
11
+ name.force_encoding('iso-8859-1').encode!('utf-8')
12
+ banks[code] = [name, bic]
13
+ end
14
+ end
15
+
7
16
  def initialize bank_code
8
17
  validate_bank_code bank_code
9
- @bank_data = load_table_row bank_code
18
+ @bank_data = BANKS[bank_code]
10
19
  raise BankNotFoundError unless @bank_data
11
20
  end
12
21
 
13
22
  def bank_name
14
- @bank_data[1]
23
+ @bank_data[0]
15
24
  end
16
25
 
17
26
  def bic
18
- @bank_data[2]
27
+ @bank_data[1]
19
28
  end
20
29
 
21
30
  def validate_bank_code bank_code
@@ -25,19 +34,5 @@ module SwiftBic
25
34
  raise InvalidBankCodeError
26
35
  end
27
36
  end
28
-
29
- private
30
-
31
- def load_table_row bank_code
32
- begin
33
- db = SQLite3::Database.open(File.expand_path("../../../db/blz.db", __FILE__))
34
- row = db.execute("SELECT * FROM blz WHERE blz = '#{bank_code}'")
35
- rescue SQLite3::Exception => e
36
- throw e
37
- ensure
38
- db.close
39
- end
40
- row[0]
41
- end
42
37
  end
43
38
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibanizator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Christoph Stettner
@@ -10,29 +9,7 @@ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
  date: 2013-05-06 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: sqlite3
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.3'
22
- - - ! '>='
23
- - !ruby/object:Gem::Version
24
- version: 1.3.7
25
- type: :runtime
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '1.3'
33
- - - ! '>='
34
- - !ruby/object:Gem::Version
35
- version: 1.3.7
12
+ dependencies: []
36
13
  description: ibanizator generates the correct IBAN for given account number and bank
37
14
  number for german accounts. It is possible to validate given international IBANS.
38
15
  Calculates also the BIC and bank names for given german bank codes.
@@ -45,31 +22,30 @@ files:
45
22
  - lib/iban/validator.rb
46
23
  - lib/iban/lengths.rb
47
24
  - lib/swift_bic/bank_db.rb
48
- - db/blz.db
25
+ - db/blz.txt
49
26
  - lib/errors/bank_not_found_error.rb
50
27
  - lib/errors/invalid_bank_code_error.rb
51
28
  homepage: https://github.com/softwareinmotion/ibanizator
52
29
  licenses: []
30
+ metadata: {}
53
31
  post_install_message:
54
32
  rdoc_options: []
55
33
  require_paths:
56
34
  - lib
57
35
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
36
  requirements:
60
- - - ! '>='
37
+ - - '>='
61
38
  - !ruby/object:Gem::Version
62
39
  version: '0'
63
40
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
41
  requirements:
66
- - - ! '>='
42
+ - - '>='
67
43
  - !ruby/object:Gem::Version
68
44
  version: '0'
69
45
  requirements: []
70
46
  rubyforge_project:
71
- rubygems_version: 1.8.24
47
+ rubygems_version: 2.0.3
72
48
  signing_key:
73
- specification_version: 3
49
+ specification_version: 4
74
50
  summary: An IBAN generator/validator and BIC generator for german accounts.
75
51
  test_files: []
data/db/blz.db DELETED
Binary file