iban-tools 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a70a2f9aeb3b139da9d84a9f50869b36541a86aa
4
+ data.tar.gz: a19616dd03eb8bbd6518b679dc80523896b0d473
5
+ SHA512:
6
+ metadata.gz: 1575260ee396f4c6c37333c718e66bdf0835cf887faae159cef5ba6c8024d455c55c1fc7ca7b954ae58a18c4025fbeba403bfc305c6d01db97b83e0f614c8ac3
7
+ data.tar.gz: d32b4e7856f27ec9f7aa20408ff2938df2c379cb333d428bf42741ae9a575189869619fd93a4f3d231b402aa1b23f0f327492091a7973e2f517aaa3d8ca8d24b
data/README.md CHANGED
@@ -35,4 +35,4 @@ Pretty print, canonicalize, and extract fields from an IBAN code
35
35
 
36
36
  ## Credit
37
37
 
38
- [Iulianu](http://github.com/iulianu) wrote [iban-tools](http://github.com/iulianu/iban-tools). ([AlphaSights](http://dev.alphasights.com)) is now maintaining the gem.
38
+ [Iulianu](http://github.com/iulianu) wrote [iban-tools](http://github.com/iulianu/iban-tools). ([AlphaSights](http://dev.alphasights.com)) is now maintaining the gem.
@@ -22,5 +22,6 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #++
24
24
 
25
+ require 'iban-tools/conversion.rb'
25
26
  require 'iban-tools/iban.rb'
26
27
  require 'iban-tools/iban_rules.rb'
@@ -0,0 +1,40 @@
1
+ module IBANTools
2
+ class Conversion
3
+
4
+ def self.local2iban(country_code, data)
5
+ config = load_config country_code
6
+
7
+ bban = config.map do |key, value|
8
+ value[1] % data[key.to_sym]
9
+ end.join('')
10
+
11
+ check_digits = "%02d" % checksum(country_code, bban)
12
+
13
+ IBAN.new "#{country_code}#{check_digits}#{bban}"
14
+ end
15
+
16
+
17
+ def self.iban2local(country_code, bban)
18
+ config = load_config country_code
19
+
20
+ local = {}
21
+ config.map do |key, value|
22
+ local[key.to_sym] = bban.scan(/^#{value[0]}/).first.sub(/^0+/, '')
23
+ bban.sub! /^#{value[0]}/, ''
24
+ end
25
+ local
26
+ end
27
+
28
+ private
29
+
30
+ def self.load_config(country_code)
31
+ default_config = YAML.
32
+ load(File.read(File.dirname(__FILE__) + '/conversion_rules.yml'))
33
+ default_config[country_code]
34
+ end
35
+
36
+ def self.checksum(country_code, bban)
37
+ 97 - (IBAN.new("#{country_code}00#{bban}").numerify.to_i % 97) + 1
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ 'DE':
2
+ blz: ['\d{8}', "%08d"]
3
+ account_number: ['\d{10}', "%010d"]
@@ -7,10 +7,27 @@ module IBANTools
7
7
  new(code).validation_errors(rules).empty?
8
8
  end
9
9
 
10
+ def self.canonicalize_code( code )
11
+ code.strip.gsub(/\s+/, '').upcase
12
+ end
13
+
14
+ # Load and cache the default rules from rules.yml
15
+ def self.default_rules
16
+ @default_rules ||= IBANRules.defaults
17
+ end
18
+
19
+ def self.from_local(country_code, data)
20
+ Conversion.local2iban country_code, data
21
+ end
22
+
10
23
  def initialize( code )
11
24
  @code = IBAN.canonicalize_code(code)
12
25
  end
13
26
 
27
+ def to_local
28
+ Conversion.iban2local country_code, bban
29
+ end
30
+
14
31
  def validation_errors( rules = nil )
15
32
  errors = []
16
33
  return [:too_short] if @code.size < 5
@@ -74,15 +91,5 @@ module IBANTools
74
91
  def prettify
75
92
  @code.gsub(/(.{4})/, '\1 ').strip
76
93
  end
77
-
78
- def self.canonicalize_code( code )
79
- code.strip.gsub(/\s+/, '').upcase
80
- end
81
-
82
- # Load and cache the default rules from rules.yml
83
- def self.default_rules
84
- @default_rules ||= IBANRules.defaults
85
- end
86
-
87
94
  end
88
95
  end
@@ -158,7 +158,7 @@
158
158
  'KZ':
159
159
  # Kazakhstan
160
160
  length: 20
161
- bban_pattern: '\d{3}[A-Z]{3}\d{10}'
161
+ bban_pattern: '\d{3}[A-Z0-9]{13}'
162
162
 
163
163
  'LB':
164
164
  # Lebanon
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iban-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 0.0.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Iulian Dogariu
@@ -10,8 +9,36 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-02-22 00:00:00.000000000 Z
14
- dependencies: []
12
+ date: 2013-04-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: coveralls
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
15
42
  description: Validates IBAN account numbers
16
43
  email:
17
44
  - code@iuliandogariu.com
@@ -22,32 +49,33 @@ extra_rdoc_files: []
22
49
  files:
23
50
  - README.md
24
51
  - lib/iban-tools.rb
52
+ - lib/iban-tools/conversion.rb
53
+ - lib/iban-tools/conversion_rules.yml
25
54
  - lib/iban-tools/iban.rb
26
55
  - lib/iban-tools/iban_rules.rb
27
56
  - lib/iban-tools/rules.yml
28
57
  homepage:
29
58
  licenses: []
59
+ metadata: {}
30
60
  post_install_message:
31
61
  rdoc_options: []
32
62
  require_paths:
33
63
  - lib
34
64
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
65
  requirements:
37
- - - ! '>='
66
+ - - '>='
38
67
  - !ruby/object:Gem::Version
39
68
  version: '0'
40
69
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
70
  requirements:
43
- - - ! '>='
71
+ - - '>='
44
72
  - !ruby/object:Gem::Version
45
73
  version: '0'
46
74
  requirements:
47
75
  - none
48
76
  rubyforge_project:
49
- rubygems_version: 1.8.11
77
+ rubygems_version: 2.0.0
50
78
  signing_key:
51
- specification_version: 3
79
+ specification_version: 4
52
80
  summary: IBAN validator
53
81
  test_files: []