ibanizator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/ibanizator.rb +44 -0
  2. metadata +46 -0
data/lib/ibanizator.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Ibanizator
2
+ def calculate_iban options
3
+ # Error handling
4
+ # TODO
5
+
6
+ # Fill account number to 10 digits
7
+ while options[:account_number].size < 10 do
8
+ options[:account_number].insert(0, '0')
9
+ end
10
+
11
+ country_code_num = character_to_digit options[:country_code].to_s
12
+ checksum = calculate_checksum options[:bank_code], options[:account_number], country_code_num
13
+
14
+ options[:country_code].to_s.upcase + checksum + options[:bank_code] + options[:account_number]
15
+ end
16
+
17
+ def validate_iban iban
18
+ country_codes = { :de => 22 }
19
+ country_code = iban[0..1].downcase.to_sym
20
+ checksum = iban[2..3]
21
+
22
+ # Error handling
23
+ if country_codes[country_code]
24
+ raise '' if iban.length != 22
25
+ else
26
+ raise ''
27
+ end
28
+
29
+ # Works only for Germany
30
+ calculated_checksum = calculate_checksum iban[4..11], iban[12..22], character_to_digit(country_code.to_s)
31
+
32
+ checksum == calculated_checksum ? true : false
33
+ end
34
+
35
+ def character_to_digit char
36
+ char.upcase!.split('').inject('') { |code, c| code + (c.ord - 55).to_s }
37
+ end
38
+
39
+ def calculate_checksum bank_code, account_number, country_code_num
40
+ x = (bank_code + account_number + country_code_num + '00').to_i % 97
41
+ checksum = (98 - x).to_s
42
+ checksum.length == 1 ? checksum.insert(0, '0') : checksum
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ibanizator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christoph Stettner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ibanizator generates the correct IBAN for given account number and bank
15
+ number for german accounts.
16
+ email: christoph.stettner@softwareinmotion.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/ibanizator.rb
22
+ homepage: https://github.com/softwareinmotion/ibanizator
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: An IBAN generator for german accounts.
46
+ test_files: []