luhnmod10 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/luhnmod10.rb +25 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdb5e3f3b12dff7f6e25beeb204d1f71358aed7f
4
+ data.tar.gz: dd2727953d8d92121d461e86aec8217c7d79c405
5
+ SHA512:
6
+ metadata.gz: 8d073d9107765f0f30d12e36b088851d53231c57706e5348dbcefc066139a7b1c6aaebe7de984aa6f132a6a28d722c6bcab4f05dc601e75cc2f4f2c13e11a22c
7
+ data.tar.gz: 08767c2d54ca5d34195d1d72c745274f1bb5dea0628488863fe3873dcdcd94671acf61df340c82d1db6768648dc6512a911ec5ce8f7667b02c0738631912507c
data/lib/luhnmod10.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Luhnmod10
2
+ def self.valid?(number)
3
+ checksum = 0
4
+
5
+ number_len = number.length
6
+
7
+ i = number_len - 1
8
+ while i >= 0 do
9
+ n = number[i].to_i
10
+ checksum += n
11
+ i -= 2
12
+ end
13
+
14
+ i = number_len - 2
15
+ while i >= 0 do
16
+ n = number[i].to_i
17
+ n *= 2
18
+ n -= 9 if n > 9
19
+ checksum += n
20
+ i -= 2
21
+ end
22
+
23
+ checksum%10 == 0
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: luhnmod10
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Leigh McCulloch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple fast implementation of the Luhn algorithm.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/luhnmod10.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A simple fast implementation of the Luhn algorithm.
44
+ test_files: []