check_digit 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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGVlNWIwODBlZTE0NzI4Y2IxOGJiYTUyZjA4NWJhMGVlZmMyMzcwMQ==
4
+ MjJmZmU2MmFiMzBmYmY4MWIzYWU4MzhkMjJkMDUxMjRlOTcxOWU0ZA==
5
5
  data.tar.gz: !binary |-
6
- NDQ3NmJhMThkZDIzMTZiZjk3OGRmNDVmM2MyNjdhNjBmYTM3ZjQ3Yw==
6
+ NDNlODkyNThmOTg5MGIzZDc4ZTdmMjgzOTJjNzNiZTQ5MDRiYmFlMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTdmNzhiZjhlMGJlOTk3YzlmMTQ3MjZjYmU4YTFhMjM5YmQ1MThlODkzMmE0
10
- ZDJiODFhZGMzZmNmMzY4YmMzZGJmNjE2Zjg3ZWQ2MGExMjJiNzhjNWRmZGU5
11
- YWJhYTRhZjNhMDk0NTJhOTExODNkMTEzYzhmZjMyMGM2ZDMyN2E=
9
+ NDViOGQxYjE4ZmJjNzQ2MWQxMjg4MzY1ZjFlMDE0ZmVkNmUxNjBhZDU0ZTI1
10
+ ZDQyNjIxZDY4MjBiMTMxYjg0MDYxYjc0NDBhMzFiMzhmNTE3MWE5OWJhZGMz
11
+ NmFjNTU4NDJlYmU2MmViYmJjZTMzZmVjNGMyZjIyNTE3ZTYyY2E=
12
12
  data.tar.gz: !binary |-
13
- ZjBmYWIzMmM3NjEzMzI4YjZjMGRmYTAxOTI0OWUxNjkxOTg5MzVhZWJjMjhk
14
- ODdjMDM5OTE1MzZhNmU5ZWY5YmE3MDI5YTVkODhkMjcyZTMyNGU1ODUyMjgz
15
- YzY3YTAwNDg2OGRkMzNkMzVlMDEyNmFiNmY5ODA1YmJmZGM5YjY=
13
+ NWIxNmNjZTI1N2I0ZDA5ZDNiN2IwY2NlNjMxMjEzZDI5M2E3N2EwMjhlNzVl
14
+ Yzg4MWU4ZTg4ODJmNDYxMzFlMDczZWY0NmJiNGI0Yjk5M2E1ZmYwYmEzODM3
15
+ NDhiYzMxNTM3MGZlOWNmOTM2ZmQ1MmQ0NTQ5YWY2YjkwZDA2Mjc=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CheckDigit
1
+ # CheckDigit [![Gem Version](https://badge.fury.io/rb/check_digit.svg)](http://badge.fury.io/rb/check_digit)
2
2
 
3
3
  Ruby implementation of the Luhn, Damm and Verhoeff check digit algorithms
4
4
 
@@ -60,7 +60,7 @@ Source: http://www.augustana.ab.ca/~mohrj/algorithms/checkdigit.html
60
60
  | Damm | 1.700000 | 1.610000 |
61
61
  | Verhoeff | 3.730000 | 3.720000 |
62
62
 
63
- \* Test was on Linux 10.04 with 2.80GHz Intel Xeon E5-1603 - relative timing is more important to consider
63
+ \* Test was on Linux 14.04 with 2.80GHz Intel Xeon E5-1603 - relative timing is more important to consider when comparing performance
64
64
 
65
65
  ## Contributing
66
66
 
@@ -1,4 +1,15 @@
1
1
  module CheckDigit::Damm
2
+ def self.checksum(num)
3
+ CheckDigit::Util.valid_arg(num)
4
+ num.to_i * 10 + calc(num)
5
+ end
6
+
7
+ def self.valid?(num)
8
+ CheckDigit::Util.valid_arg(num)
9
+ calc(num.to_s[0..-2]) == num % 10
10
+ end
11
+
12
+ private
2
13
  D = [
3
14
  [0, 3, 1, 7, 5, 9, 8, 6, 4, 2],
4
15
  [7, 0, 9, 2, 1, 5, 4, 8, 6, 3],
@@ -12,17 +23,6 @@ module CheckDigit::Damm
12
23
  [2, 5, 8, 1, 4, 3, 6, 7, 9, 0]
13
24
  ].freeze
14
25
 
15
- def self.checksum(num)
16
- CheckDigit::Util.valid_arg(num)
17
- num.to_i * 10 + calc(num)
18
- end
19
-
20
- def self.valid?(num)
21
- CheckDigit::Util.valid_arg(num)
22
- calc(num.to_s[0..-2]) == num % 10
23
- end
24
-
25
- private
26
26
  def self.calc(num)
27
27
  i = 0
28
28
  num.to_s.each_char {|c| i = D[i][c.to_i] }
@@ -1,4 +1,15 @@
1
1
  module CheckDigit::Verhoeff
2
+ def self.checksum(num)
3
+ CheckDigit::Util.valid_arg(num)
4
+ num.to_i * 10 + calc(num)
5
+ end
6
+
7
+ def self.valid?(num)
8
+ CheckDigit::Util.valid_arg(num)
9
+ calc(num.to_s[0..-2]) == num % 10
10
+ end
11
+
12
+ private
2
13
  D = [
3
14
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
4
15
  [1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
@@ -27,17 +38,6 @@ module CheckDigit::Verhoeff
27
38
 
28
39
  ZERO_ORDINAL = 48 # '0'.each_byte.first on 1.8 or '0'.ord on 1.9
29
40
 
30
- def self.checksum(num)
31
- CheckDigit::Util.valid_arg(num)
32
- num.to_i * 10 + calc(num)
33
- end
34
-
35
- def self.valid?(num)
36
- CheckDigit::Util.valid_arg(num)
37
- calc(num.to_s[0..-2]) == num % 10
38
- end
39
-
40
- private
41
41
  def self.calc(num)
42
42
  INV[num.to_s.each_byte.reverse_each.with_index.inject(0) { |check,(x,i)|
43
43
  D[check][P[i.next % 8][x - ZERO_ORDINAL]]
@@ -1,3 +1,3 @@
1
1
  module CheckDigit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_digit
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
  - Eric Litwin