bank-validator 0.2.8 → 0.3.0

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: f49faff0bcd5e27910cf566ce176927797ecf639
4
- data.tar.gz: 9c3eef67cf8c6a4d777bb6226691fd1c4ab2b88e
3
+ metadata.gz: b555b0a31162c5401f195c2347a9ab24136f7b69
4
+ data.tar.gz: c858334dcf134a1b6b0e6a10add483c3c6f37554
5
5
  SHA512:
6
- metadata.gz: 8892e7baee39182971b77f7796a361315af96de85aa1128573eb389830905f118dcb7a3df2c7c34bdb914e7a006c5e069ca887f6883ce8c5110f53978693ea98
7
- data.tar.gz: e7810dfe4e9e4b61d7ef748e3dc9b91467485c762e315c35f42f4050386c896c376a25d91780bd91820d438021fb324a8be7bca3c4d2e47fcdf9941f598724c0
6
+ metadata.gz: 18dd893ad4cc4c58c0f504ba001910e34a28f8ec916f024b956950d6f6bfdd465436542454faa36782aab33bb6ce35546f3f7c557dcaf91cf397b35a0902a0f1
7
+ data.tar.gz: 57b602770bccd01665d4a93df66d75357ed87f3eed0672177eb7c8b17489f4185f6996030eeffb1f7ac4f03e27e5dd6766cbabab30d040403d153e3a390f798d
@@ -97,3 +97,6 @@ DEPENDENCIES
97
97
  rspec
98
98
  shoulda (~> 3.5)
99
99
  simplecov (~> 0.9)
100
+
101
+ BUNDLED WITH
102
+ 1.10.6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.3.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bank-validator 0.2.8 ruby lib
5
+ # stub: bank-validator 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bank-validator"
9
- s.version = "0.2.8"
9
+ s.version = "0.3.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Adam Bahlke"]
14
- s.date = "2015-04-20"
14
+ s.date = "2016-01-28"
15
15
  s.description = "Validates IBAN and BIC account numbers. Still a work in progress"
16
16
  s.email = "adam.bahlke@hitfoxgroup.com"
17
17
  s.extra_rdoc_files = [
@@ -31,7 +31,11 @@ Gem::Specification.new do |s|
31
31
  "lib/active_model/bic_validator.rb",
32
32
  "lib/active_model/iban_validator.rb",
33
33
  "lib/active_model/routing_number_validator.rb",
34
+ "lib/activemodel.rb",
34
35
  "lib/bank-validator.rb",
36
+ "lib/bank_validator/bic.rb",
37
+ "lib/bank_validator/iban.rb",
38
+ "lib/bank_validator/routing_number.rb",
35
39
  "test/dummy/.gitignore",
36
40
  "test/dummy/.rspec",
37
41
  "test/dummy/Gemfile",
@@ -1,9 +1,7 @@
1
- require 'active_model'
2
-
3
1
  class BicValidator < ActiveModel::EachValidator
4
2
 
5
3
  def validate_each(record, attribute, value)
6
- record_error(record, attribute, value) unless value =~ BicValidator.regexp
4
+ record_error(record, attribute, value) unless BankValidator::Bic.new(value).valid?
7
5
  end
8
6
 
9
7
  private
@@ -11,8 +9,4 @@ class BicValidator < ActiveModel::EachValidator
11
9
  def record_error(record, attribute, value)
12
10
  record.errors.add(attribute, (options[:message] || :invalid_bic))
13
11
  end
14
-
15
- def self.regexp
16
- /[A-Z]{6}[A-Z0-9]{2,}/
17
- end
18
12
  end
@@ -1,9 +1,7 @@
1
- require 'active_model'
2
-
3
1
  class IbanValidator < ActiveModel::EachValidator
4
2
 
5
3
  def validate_each(record, attribute, value)
6
- record_error(record, attribute, value) unless value =~ IbanValidator.regexp && valid_iban?(value)
4
+ record_error(record, attribute, value) unless BankValidator::Iban.new(value).valid?
7
5
  end
8
6
 
9
7
 
@@ -12,19 +10,4 @@ class IbanValidator < ActiveModel::EachValidator
12
10
  def record_error(record, attribute, value)
13
11
  record.errors.add(attribute, (options[:message] || :invalid_iban))
14
12
  end
15
-
16
- def self.regexp
17
- /[A-Z]{2}[a-zA-Z0-9]{14,}/
18
- end
19
-
20
- def valid_iban?(iban)
21
- # Move first four characters to end of string
22
- dummy_iban = iban[4..-1] + iban[0..3]
23
-
24
- # Substitute all letters with integers
25
- checksum = dummy_iban.chars.map { |char| ((char =~ /[a-zA-Z]/).present?) ? (char.downcase.ord - 87).to_s : char }.join
26
-
27
- # Check if division by 97 yields a remainder of 1, in which case it could be a valid IBAN
28
- (checksum.to_i % 97) == 1
29
- end
30
13
  end
@@ -1,9 +1,7 @@
1
- require 'active_model'
2
-
3
1
  class RoutingNumberValidator < ActiveModel::EachValidator
4
2
 
5
3
  def validate_each(record, attribute, value)
6
- record_error(record, attribute, value) unless value =~ RoutingNumberValidator.regexp && valid_routing_number?(value)
4
+ record_error(record, attribute, value) unless BankValidator::RoutingNumber.new(value).valid?
7
5
  end
8
6
 
9
7
  private
@@ -11,18 +9,4 @@ class RoutingNumberValidator < ActiveModel::EachValidator
11
9
  def record_error(record, attribute, value)
12
10
  record.errors.add(attribute, (options[:message] || :invalid_routing_number))
13
11
  end
14
-
15
- def self.regexp
16
- /^[0-9]{9}$/
17
- end
18
-
19
- def valid_routing_number?(route_number)
20
- d = route_number.each_char.to_a
21
-
22
- (weighted_value(1, d, [2, 5, 8]) + weighted_value(3, d, [0, 3, 6]) + weighted_value(7, d, [1, 4, 7])) % 10 == 0
23
- end
24
-
25
- def weighted_value(weight, array, indexes)
26
- weight * array.values_at(*indexes).collect! {|v| v.to_i}.inject(:+)
27
- end
28
12
  end
@@ -0,0 +1,4 @@
1
+ require 'active_model'
2
+ require 'active_model/iban_validator'
3
+ require 'active_model/bic_validator'
4
+ require 'active_model/routing_number_validator'
@@ -1,9 +1,5 @@
1
- require_relative './active_model/iban_validator'
2
- require_relative './active_model/bic_validator'
3
- require_relative './active_model/routing_number_validator'
1
+ require 'bank_validator/iban'
2
+ require 'bank_validator/bic.rb'
3
+ require 'bank_validator/routing_number.rb'
4
4
 
5
- module ActiveModel
6
- autoload :IbanValidator, './active_model/iban_validator'
7
- autoload :BicValidator, './active_model/bic_validator'
8
- autoload :RoutingNumberValidator, './active_model/routing_number_validator'
9
- end
5
+ require 'activemodel'
@@ -0,0 +1,17 @@
1
+ module BankValidator
2
+ class Bic
3
+ attr_accessor :value
4
+
5
+ def initialize(bic)
6
+ @value = bic
7
+ end
8
+
9
+ def valid?
10
+ BankValidator::Bic.valid_format?(value)
11
+ end
12
+
13
+ def self.valid_format?(bic)
14
+ bic =~ /[A-Z]{6}[A-Z0-9]{2,}/ ? true : false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module BankValidator
2
+ class Iban
3
+ attr_accessor :value
4
+
5
+ def initialize(iban)
6
+ @value = iban
7
+ end
8
+
9
+ def valid?
10
+ BankValidator::Iban.valid_format?(value) && BankValidator::Iban.valid_checksum?(value)
11
+ end
12
+
13
+ class << self
14
+ def valid_format?(iban)
15
+ iban =~ /[A-Z]{2}[a-zA-Z0-9]{14,}/ ? true : false
16
+ end
17
+
18
+ def valid_checksum?(iban)
19
+ # Move first four characters to end of string
20
+ dummy_iban = iban[4..-1] + iban[0..3]
21
+
22
+ # Substitute all letters with integers
23
+ checksum = dummy_iban.chars.map { |char| ((char =~ /[a-zA-Z]/).present?) ? (char.downcase.ord - 87).to_s : char }.join
24
+
25
+ # Check if division by 97 yields a remainder of 1, in which case it could be a valid IBAN
26
+ (checksum.to_i % 97) == 1
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module BankValidator
2
+ class RoutingNumber
3
+ attr_accessor :value
4
+
5
+ def initialize(routing_number)
6
+ @value = routing_number
7
+ end
8
+
9
+ def valid?
10
+ BankValidator::RoutingNumber.valid_format?(value) && BankValidator::RoutingNumber.valid_routing_number?(value)
11
+ end
12
+
13
+ class << self
14
+ def valid_routing_number?(routing_number)
15
+ d = routing_number.each_char.to_a
16
+
17
+ (BankValidator::RoutingNumber.weighted_value(1, d, [2, 5, 8]) + BankValidator::RoutingNumber.weighted_value(3, d, [0, 3, 6]) + BankValidator::RoutingNumber.weighted_value(7, d, [1, 4, 7])) % 10 == 0
18
+ end
19
+
20
+ def valid_format?(routing_number)
21
+ routing_number =~ /^[0-9]{9}$/ ? true : false
22
+ end
23
+
24
+ def weighted_value(weight, array, indexes)
25
+ weight * array.values_at(*indexes).collect! {|v| v.to_i}.inject(:+)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -39,6 +39,7 @@ group :development, :test do
39
39
  gem 'rspec'
40
40
  # Access an IRB console on exception pages or by using <%= console %> in views
41
41
  gem 'web-console', '~> 2.0'
42
+ gem 'pry'
42
43
 
43
44
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
44
45
  gem 'spring'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ~/Workspace/bank-validator
3
3
  specs:
4
- bank-validator (0.2.7)
4
+ bank-validator (0.3.0)
5
5
  activemodel (>= 3.0)
6
6
 
7
7
  GEM
@@ -48,6 +48,7 @@ GEM
48
48
  builder (3.2.2)
49
49
  byebug (4.0.4)
50
50
  columnize (= 0.9.0)
51
+ coderay (1.1.0)
51
52
  coffee-rails (4.1.0)
52
53
  coffee-script (>= 2.2.0)
53
54
  railties (>= 4.0.0, < 5.0)
@@ -76,12 +77,17 @@ GEM
76
77
  nokogiri (>= 1.5.9)
77
78
  mail (2.6.3)
78
79
  mime-types (>= 1.16, < 3)
80
+ method_source (0.8.2)
79
81
  mime-types (2.4.3)
80
82
  mini_portile (0.6.2)
81
83
  minitest (5.5.1)
82
84
  multi_json (1.11.0)
83
85
  nokogiri (1.6.6.2)
84
86
  mini_portile (~> 0.6.0)
87
+ pry (0.10.3)
88
+ coderay (~> 1.1.0)
89
+ method_source (~> 0.8.1)
90
+ slop (~> 3.4)
85
91
  rack (1.6.0)
86
92
  rack-test (0.6.3)
87
93
  rack (>= 1.0)
@@ -135,6 +141,7 @@ GEM
135
141
  sdoc (0.4.1)
136
142
  json (~> 1.7, >= 1.7.7)
137
143
  rdoc (~> 4.0)
144
+ slop (3.6.0)
138
145
  spring (1.3.3)
139
146
  sprockets (2.12.3)
140
147
  hike (~> 1.2)
@@ -171,6 +178,7 @@ DEPENDENCIES
171
178
  coffee-rails (~> 4.1.0)
172
179
  jbuilder (~> 2.0)
173
180
  jquery-rails
181
+ pry
174
182
  rails (= 4.2.1)
175
183
  rspec
176
184
  sass-rails (~> 5.0)
@@ -180,3 +188,6 @@ DEPENDENCIES
180
188
  turbolinks
181
189
  uglifier (>= 1.3.0)
182
190
  web-console (~> 2.0)
191
+
192
+ BUNDLED WITH
193
+ 1.10.6
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bahlke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -128,7 +128,11 @@ files:
128
128
  - lib/active_model/bic_validator.rb
129
129
  - lib/active_model/iban_validator.rb
130
130
  - lib/active_model/routing_number_validator.rb
131
+ - lib/activemodel.rb
131
132
  - lib/bank-validator.rb
133
+ - lib/bank_validator/bic.rb
134
+ - lib/bank_validator/iban.rb
135
+ - lib/bank_validator/routing_number.rb
132
136
  - test/dummy/.gitignore
133
137
  - test/dummy/.rspec
134
138
  - test/dummy/Gemfile