ibanify 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3e2f41ee59987f85b535e3c82b2d96c5a39b03a
4
- data.tar.gz: eec6ac496177f916dc1f183359adc3231186636f
3
+ metadata.gz: bb8f9fe1f23dd43fe0644203ba1ab9b4ffb4c5b4
4
+ data.tar.gz: 2b1ac667c72a0d540bda2c47e69ff2871433b29f
5
5
  SHA512:
6
- metadata.gz: 734d6f438073d3d81068242185418fbe7260a530f946c75dc5fabab9ecfd8ba6aff27dbfad9e80ba1da350303b78ef11448f1f4fc70cd923355550955458b4e4
7
- data.tar.gz: 573b3fb9bffd8d44db5e87ab67d2e98bed162c041a0086fa3a050e50c40a03aa071fa40f83d06b92054e0546b013912d79965125da6bce97245645fdf7b00bff
6
+ metadata.gz: 0feee19bc6989c387f9f074e90fdafe898bb196ceafcef4d9b2ac69727d47b11fd9a5f7ef9d48cc90cae57b1cfd1f0076e95b952b83aba729b87141e7e08a7e1
7
+ data.tar.gz: 56bba9ac0d2424bd27254b3d16c153f2941096e45448eaa659ca89c2e995071f0ec2eec86c261f5bca850bde140f356bb7607340f0acd53c1f2c6dda24369924
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Ibanify
2
2
 
3
- Ruby library for validating IBAN using openiban.com REST Webservice. https://openiban.com
3
+ Ruby library for validating IBAN. Currently only working for the following countries:
4
+
5
+ - France
6
+ - United Kingdom
7
+ - Sweden
4
8
 
5
9
  ## Installation
6
10
 
@@ -25,8 +29,8 @@ Or install it yourself as:
25
29
  Ibanify::IBAN.valid?('SE45 5000 0000 0583 9825 7466')
26
30
  => true
27
31
 
28
- Ibanify::IBAN.new('INVALID').validation_error
29
- => :invalid_iban
32
+ Ibanify::IBAN.new('SE45 5000 0000 0583 9825 746').validation_error
33
+ => :invalid_length
30
34
 
31
35
  ## License
32
36
 
data/ibanify.gemspec CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "httparty", "~> 0.14"
22
-
23
21
  spec.add_development_dependency "bundler", "~> 1.12"
24
22
  spec.add_development_dependency "rake", "~> 10.0"
25
23
  spec.add_development_dependency "rspec", "~> 3.0"
data/lib/ibanify.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'httparty'
1
+ require 'yaml'
2
2
  require 'ibanify/version'
3
+ require 'ibanify/countries.rb'
3
4
 
4
5
  module Ibanify
5
6
  class IBAN
@@ -12,21 +13,46 @@ module Ibanify
12
13
  end
13
14
 
14
15
  def validation_error
15
- return :invalid_chars unless @number =~ /^[A-Z0-9]+$/
16
- return :invalid_iban unless valid_iban?
16
+ return :invalid_country_code unless countries[country_code]
17
+ return :invalid_length unless countries[country_code]['length'] == @number.size
18
+ return :invalid_bban unless bban =~ countries[country_code]['bban']
19
+ return :invalid_check_digits unless valid_check_digits?
17
20
  end
18
21
 
19
- def valid_iban?
20
- url = "https://openiban.com/validate/#{@number}"
21
- response = HTTParty.get(url)
22
- data = response.parsed_response
23
- data['valid'] == true
22
+ def valid_check_digits?
23
+ iban = @number[4..-1] + @number[0, 4]
24
+ iban.gsub!(/./) do |c|
25
+ c.to_i(36)
26
+ end
27
+
28
+ iban.to_i % 97 == 1
24
29
  end
25
30
 
26
31
  def number
27
32
  @number
28
33
  end
29
34
 
35
+ def country_code
36
+ @number[0..1]
37
+ end
38
+
39
+ def bban
40
+ @number[4..-1]
41
+ end
42
+
43
+ def countries
44
+ load_countries_from_string(File.read(File.dirname(__FILE__) + '/ibanify/countries.yml'))
45
+ end
46
+
47
+ def load_countries_from_string(string)
48
+ hash = YAML.load(string)
49
+ hash.each do |country_code, rules|
50
+ rules['bban'] = Regexp.new('^' + rules['bban'] + '$')
51
+ end
52
+
53
+ Countries.new(hash)
54
+ end
55
+
30
56
  def self.normalize(number)
31
57
  number.strip.gsub(/\s+/, '').upcase
32
58
  end
@@ -0,0 +1,11 @@
1
+ module Ibanify
2
+ class Countries
3
+ def initialize(countries = {})
4
+ @countries = countries
5
+ end
6
+
7
+ def [](key)
8
+ @countries[key]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # Examples from http://www.xe.com/ibancalculator/countrylist/
2
+
3
+ # France
4
+ 'FR':
5
+ length: 27
6
+ bban: '\d{10}[A-Z0-9]{11}\d{2}'
7
+
8
+ # United Kingdom
9
+ 'GB':
10
+ length: 22
11
+ bban: '[A-Z]{4}\d{14}'
12
+
13
+ # Sweden
14
+ 'SE':
15
+ length: 24
16
+ bban: '\d{20}'
@@ -1,3 +1,3 @@
1
1
  module Ibanify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibanify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Almstrand
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: httparty
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.14'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.14'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +70,8 @@ files:
84
70
  - bin/setup
85
71
  - ibanify.gemspec
86
72
  - lib/ibanify.rb
73
+ - lib/ibanify/countries.rb
74
+ - lib/ibanify/countries.yml
87
75
  - lib/ibanify/version.rb
88
76
  homepage: https://github.com/tobiasalmstrand/ibanify
89
77
  licenses: