luhn 1.0.2 → 2.0.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
- SHA1:
3
- metadata.gz: eece57290c12c551a1673bac68bbaf0b9674c5b2
4
- data.tar.gz: e86edca6abea3b65d71edddef8114d65e1b2015c
2
+ SHA256:
3
+ metadata.gz: 1ff23cbc7129b7601b34777ba537836b0208bf923e20dba0d487b0f6c3820b7d
4
+ data.tar.gz: ef77324153e382df6f5ca8acd7f4f463a2b26c112697125b46fb45ac5e0524a4
5
5
  SHA512:
6
- metadata.gz: 9149f14748ef4a961500f622dd114702f8c100c0425f75bddd0f1fae842a443139102598417aef83fc3d0d0dd9cec4d0bb0e26d037e6555e278d82ad8489cec3
7
- data.tar.gz: 03dd2de39b1698ec77d947db29dc297cf4eb4d2ceec23e31170cd72047f67196b8da5e7f09f2ee48ba89a0b68cf92206272c4bd8f070d550b1a0b16d6efb4917
6
+ metadata.gz: 68ff8abbceae4a45d326a514d5ada5353a6fc54db0c96cd5959aff186951dde6274fff7299f2d5caf6224c4ac52a2ea4331f217586e61589705b027a79fd0257
7
+ data.tar.gz: 4c3141f268fbdc1f6764e7ebb217e6e27c18d810ee9865882eabf49c8ea1c57cf9514d39a5b12eefbdc082c114b7a997793ef4c736030622d5beaa97d357d869
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Ruby class for handling basic Luhn number generation and verification
2
+
3
+ Includes a class to handle Swedish civic numbers (Personnummer).
4
+
5
+ The interface supports checking validity (length, valid date and satisfies luhn),
6
+ returning the sex, the control digit, and generating random civic numbers.
7
+
8
+ ## Install
9
+
10
+ ```shell
11
+ $ gem install luhn
12
+ ```
13
+
14
+ ## Usage:
15
+
16
+ ### Basic Luhn
17
+
18
+ ```ruby
19
+ Luhn.valid?('0465827879483596') # true
20
+ Luhn.control_digit('046582787948359') # 6
21
+ Luhn.generate(n) # returns a random number of n length that satisfies luhn
22
+
23
+ '0465827879483596'.valid_luhn? # true
24
+ 0465827879483596.valid_luhn? # true
25
+ ```
26
+
27
+ ### Swedish civic numbers
28
+
29
+ ```ruby
30
+ civic_number = Luhn::CivicNumber.new('19391030-3183')
31
+ civic_number.valid? # true
32
+ civic_number.sex # 'male'
33
+ civic_number.male? # true
34
+ civic_number.control_digit # 3
35
+
36
+ '391030-3183'.civic_number? # true
37
+ 3910303183.civic_number? # true
38
+ ```
39
+
40
+ ## About the Luhn algorithm
41
+
42
+ The following is an excerpt from [the Wikipedia article on the Luhn algorithm.](https://en.wikipedia.org/wiki/Luhn_algorithm)
43
+
44
+ The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10"
45
+ algorithm, is a simple checksum formula used to validate a variety of
46
+ identification numbers, such as credit card numbers, IMEI numbers,
47
+ National Provider Identifier numbers in US and Canadian Social Insurance Numbers,
48
+ and even South African ID numbers.
49
+
50
+ It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent
51
+ No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.
52
+
53
+ ## Copyright
54
+
55
+ Copyright (c) 2010 Joel Junström. See [LICENSE](LICENSE) for details.
@@ -1,5 +1,4 @@
1
1
  # encoding: UTF-8
2
- require 'ostruct'
3
2
  module Luhn
4
3
  class CivicNumber
5
4
  attr_reader :value
@@ -33,11 +32,11 @@ module Luhn
33
32
  end
34
33
 
35
34
  def birth_date
36
- OpenStruct.new({
37
- :year => value[0...2].to_i,
38
- :month => value[2...4].to_i,
39
- :day => value[4...6].to_i
40
- })
35
+ Data.define(:year, :month, :day).new(
36
+ value[0...2].to_i,
37
+ value[2...4].to_i,
38
+ value[4...6].to_i
39
+ )
41
40
  end
42
41
 
43
42
  def formatted
data/lib/luhn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Luhn
2
- Version = "1.0.2"
2
+ Version = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,69 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luhn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Junström
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: minitest
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: 2.6.0
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ~>
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: 2.6.0
27
- description:
28
26
  email:
29
27
  - joel.junstrom@gmail.com
30
28
  executables: []
31
29
  extensions: []
32
30
  extra_rdoc_files: []
33
31
  files:
32
+ - LICENSE
33
+ - README.md
34
+ - lib/luhn.rb
34
35
  - lib/luhn/civic_number.rb
36
+ - lib/luhn/extensions.rb
35
37
  - lib/luhn/extensions/numeric.rb
36
38
  - lib/luhn/extensions/string.rb
37
- - lib/luhn/extensions.rb
38
39
  - lib/luhn/version.rb
39
- - lib/luhn.rb
40
40
  - spec/helper.rb
41
41
  - spec/spec_civic_number.rb
42
42
  - spec/spec_extensions.rb
43
43
  - spec/spec_luhn.rb
44
- - LICENSE
45
- - README.rdoc
46
44
  homepage: http://github.com/joeljunstrom/ruby_luhn
47
45
  licenses: []
48
46
  metadata: {}
49
- post_install_message:
50
47
  rdoc_options: []
51
48
  require_paths:
52
49
  - lib
53
50
  required_ruby_version: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - '>='
52
+ - - ">="
56
53
  - !ruby/object:Gem::Version
57
- version: '0'
54
+ version: '3.2'
58
55
  required_rubygems_version: !ruby/object:Gem::Requirement
59
56
  requirements:
60
- - - '>='
57
+ - - ">="
61
58
  - !ruby/object:Gem::Version
62
59
  version: '0'
63
60
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.0.14
66
- signing_key:
61
+ rubygems_version: 3.7.2
67
62
  specification_version: 4
68
63
  summary: A small implementation of the Luhn algorithm.
69
64
  test_files: []
data/README.rdoc DELETED
@@ -1,44 +0,0 @@
1
- = Ruby class for handling basic Luhn number generation and verification
2
-
3
- Includes a class to handle Swedish civic numbers (Personnummer)
4
- That interface supports checking validity (length, valid date and satisfies luhn),
5
- returning the sex, the control digit and generating random civic numbers.
6
-
7
- == Install
8
-
9
- $ gem install luhn
10
-
11
- == Usage:
12
-
13
- === Basic Luhn
14
-
15
- Luhn.valid?('0465827879483596') # true
16
- Luhn.control_digit('046582787948359') # 6
17
- Luhn.generate(n) # returns a random number of n length that satisfies luhn
18
-
19
- '0465827879483596'.valid_luhn? # true
20
- 0465827879483596.valid_luhn? # true
21
-
22
- === Swedish civic numbers
23
-
24
- civic_number = Luhn::CivicNumber.new('19391030-3183')
25
- civic_number.valid? # true
26
- civic_number.sex # 'male'
27
- civic_number.male? # true
28
- civic_number.control_digit # 3
29
-
30
- '391030-3183'.civic_number? # true
31
- 3910303183.civic_number? # true
32
-
33
- == About the Luhn algorithm (from http://en.wikipedia.org/wiki/Luhn_formula)
34
-
35
- The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10"
36
- algorithm, is a simple checksum formula used to validate a variety of
37
- identification numbers, such as credit card numbers, IMEI numbers,
38
- National Provider Identifier numbers in US and Canadian Social Insurance Numbers.
39
- It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent
40
- No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.
41
-
42
- == Copyright
43
-
44
- Copyright (c) 2010 Joel Junström. See LICENSE for details.