iso-iban 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0620d303ad9521d970f78c7d9241b70aff7513a4
4
- data.tar.gz: 79bef52b6e60f17fe955bf0c0bad877d27e3e758
3
+ metadata.gz: 1331caf363e5c9959e34a85b95c69a112e9b9e52
4
+ data.tar.gz: 86451b8eeb5fd428501f250cf442ba49aacc3e65
5
5
  SHA512:
6
- metadata.gz: cd61b440ccdaa0d25992b712bfb417fbfc4aadf03d66964552c0bf9e282704df8e490689aa8e1d9dbc468c877063eb437cb5e2c1bd2216aebe84d0ef075c10a7
7
- data.tar.gz: 0c159932573521ad658ac6db7d00c3fcb71b7cd607286b1064357e8216ad7c7e472536b2372d86e4266a0b287fa72ce21dc1923cd0354f2a81040181b71986c4
6
+ metadata.gz: b84ad4b9a52ffb2b1c644237f3ef462f0003746ef9ce1503039df28f46a1c52518e741f8d6335f5439503821b9d3ffeca951e0b42a13077fdf0ca07eab727a88
7
+ data.tar.gz: abc912af4577970c0708822751d206ba0b097d744290a6c13972f90e2b8837f47ae37655020db96ea93270a49bdcc199249e14a9b7f30cbf40018be075d4f8c9
data/iso-iban.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "iso-iban"
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
  s.authors = "Stefan Rusterholz"
7
7
  s.email = "stefan.rusterholz@gmail.com"
8
8
  s.homepage = "https://github.com/apeiros/iso-iban"
data/lib/iso/iban.rb CHANGED
@@ -37,7 +37,7 @@ module ISO
37
37
  # Bank identifier: The identifier that uniquely identifies the financial
38
38
  # institution and, when appropriate, the branch of that financial institution
39
39
  # servicing an account
40
- #
40
+ #
41
41
  # `In this registry, the branch identifier format is shown specifically, when
42
42
  # present.`
43
43
  #
@@ -84,11 +84,17 @@ module ISO
84
84
  elsif ENV['IBAN_SPECIFICATIONS'] then
85
85
  spec_file = ENV['IBAN_SPECIFICATIONS']
86
86
  else
87
- spec_file = File.expand_path('../../../../data/iso-iban/specs.yaml', __FILE__)
88
- spec_file = Gem.datadir('iso-iban')+'/specs.yaml' if defined?(Gem) && !File.file?(spec_file)
87
+ spec_file = File.expand_path('../../../data/iso-iban/specs.yaml', __FILE__)
88
+ if !File.file?(spec_file) && defined?(Gem) && Gem.datadir('iso-iban')
89
+ spec_file = Gem.datadir('iso-iban')+'/specs.yaml'
90
+ end
89
91
  end
90
92
 
91
- @specifications = ISO::IBAN::Specification.load_yaml(spec_file)
93
+ if spec_file && File.file?(spec_file)
94
+ @specifications = ISO::IBAN::Specification.load_yaml(spec_file)
95
+ else
96
+ raise "Could not load IBAN specifications, no specs file found."
97
+ end
92
98
 
93
99
  self
94
100
  end
@@ -105,7 +105,25 @@ module ISO
105
105
 
106
106
  # @return [Array<Integer>] An array with the lengths of all components.
107
107
  def component_lengths
108
- @bban_structure.scan(/\d+/).map(&:to_i)
108
+ [bank_code_length, branch_code_length, account_code_lenght].tap { |lengths| lengths.delete(0) }
109
+ end
110
+
111
+ # @return [Fixnum]
112
+ # The length of the bank code in the IBAN, 0 if the IBAN has no bank code.
113
+ def bank_code_length
114
+ @bank_position_from && @bank_position_to ? @bank_position_to-@bank_position_from+1 : 0
115
+ end
116
+
117
+ # @return [Fixnum]
118
+ # The length of the bank code in the IBAN, 0 if the IBAN has no branch code.
119
+ def branch_code_length
120
+ @branch_position_from && @branch_position_to ? @branch_position_to-@branch_position_from+1 : 0
121
+ end
122
+
123
+ # @return [Fixnum]
124
+ # The length of the account code in the IBAN.
125
+ def account_code_lenght
126
+ bban_length-bank_code_length-branch_code_length
109
127
  end
110
128
 
111
129
  # @return [Array] An array with the Specification properties. Used for serialization.
@@ -13,6 +13,6 @@ module ISO
13
13
  # @note
14
14
  # require 'iso/iban' loads the version.
15
15
  #
16
- Version = Gem::Version.new("0.0.1")
16
+ Version = Gem::Version.new("0.0.2")
17
17
  end
18
18
  end
@@ -7,6 +7,12 @@ suite "ISO::IBAN" do
7
7
  ISO::IBAN.instance_variable_set(:@specifications, {'CH' => ISO::IBAN::Specification.new("Switzerland", "CH", "CH2!n5!n12!c", 21, "5!n12!c", 17, 4, 8, nil, nil)})
8
8
  end
9
9
 
10
+ test 'ISO::IBAN::generate problem, TODO' do
11
+ ISO::IBAN.instance_variable_set(:@specifications, {'BG' => ISO::IBAN::Specification.new("Bulgaria", "BG", "BG2!n4!a4!n2!n8!c", 22, "4!a4!n2!n8!c", 18, 4, 7, 8, 11)})
12
+ assert ISO::IBAN.generate('BG', 'AAAA', '2', 'C').valid? # this works now
13
+ assert ISO::IBAN.generate('BG', 'A', '2', 'C').valid? # this still fails, because ISO::IBAN::generate can't pad 'a' format fields
14
+ end
15
+
10
16
  test 'ISO::IBAN::load_specifications' do
11
17
  reset_test_files
12
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso-iban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Rusterholz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-07 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  ISO::IBAN implements IBAN (International Bank Account Number) specification as per ISO 13616-1.