mod_10 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/lib/mod_10.rb +29 -0
- data/lib/mod_10/version.rb +3 -0
- data/mod_10-0.0.1.gem +0 -0
- data/mod_10-0.0.2.gem +0 -0
- data/mod_10.gemspec +23 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3fe4a77c0a4e1c5c66193ae1298c23f54d772c0a
|
4
|
+
data.tar.gz: 6f557b5c1a3f246907ad86654592f62cc3d051b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e31d235f32db6d2e99505f2e2523b4b5e644e4306c276f7e859db2d6f2355a99d651f17153e8e0dcffbd5e872035ec59dbaf148236ba286ff5c1269d158e05f
|
7
|
+
data.tar.gz: 6e9d2487bfb0e24ecefeb6f1bdac2838f5308c885ceca805f151786ac337d3a67afc7a36aff3d2d8065b1eae9f695eab17919126a275550fc8a907eafeb967b8
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kryptyk Fysh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Mod10
|
2
|
+
|
3
|
+
A simple gem to generate mod_10 check digits and check if integers are mod10
|
4
|
+
valid.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mod_10'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install mod_10
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Include the Mod10 module to make the following two methods available
|
25
|
+
- generate_check_digit(value)
|
26
|
+
Which returns an integer value for the mod10 check digit of a string or integer.
|
27
|
+
Note: If the value is 0, then the argument was already mod10 valid.
|
28
|
+
|
29
|
+
- is_mod10?(value)
|
30
|
+
Returns true or false for the tested value is it is or isn't mod10 valid.
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/mod_10/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/mod_10.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "mod_10/version"
|
2
|
+
|
3
|
+
module Mod10
|
4
|
+
# Returns the Mod10 check digit for the given value, which can be integer or
|
5
|
+
# String.
|
6
|
+
def generate_check_digit(value)
|
7
|
+
total = 0
|
8
|
+
value.to_s.reverse.split(//).map(&:to_i).each_with_index do |el, i|
|
9
|
+
el *= 2 if i.even?
|
10
|
+
if el > 9
|
11
|
+
el = el.to_s.split(//).reduce(0) { |sum, x| sum += x.to_i }
|
12
|
+
end
|
13
|
+
total += el
|
14
|
+
end
|
15
|
+
10 - total.to_s[-1].to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
# Checks if a given value has a valid Mod10 check digit.
|
19
|
+
def is_mod10?(value)
|
20
|
+
digits = value.to_s.chars.map(&:to_i)
|
21
|
+
check_digit = digits.pop
|
22
|
+
|
23
|
+
sum = digits.reverse.each_slice(2).map do |x, y|
|
24
|
+
[(x * 2).divmod(10), y || 0]
|
25
|
+
end.flatten.inject(:+)
|
26
|
+
|
27
|
+
10 - sum % 10 == check_digit
|
28
|
+
end
|
29
|
+
end
|
data/mod_10-0.0.1.gem
ADDED
Binary file
|
data/mod_10-0.0.2.gem
ADDED
Binary file
|
data/mod_10.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mod_10/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mod_10"
|
8
|
+
spec.version = Mod10::VERSION
|
9
|
+
spec.authors = ["Kryptyk Fysh"]
|
10
|
+
spec.email = ["kryptykfysh@kryptykfysh.co.uk"]
|
11
|
+
spec.summary = %q{Generates mod10 check digits and checks if values already are valid mod10.}
|
12
|
+
spec.description = File.read('README.md')
|
13
|
+
spec.homepage = "https://github.com/kryptykfysh/mod_10"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mod_10
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kryptyk Fysh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: |
|
42
|
+
# Mod10
|
43
|
+
|
44
|
+
A simple gem to generate mod_10 check digits and check if integers are mod10
|
45
|
+
valid.
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
Add this line to your application's Gemfile:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
gem 'mod_10'
|
53
|
+
```
|
54
|
+
|
55
|
+
And then execute:
|
56
|
+
|
57
|
+
$ bundle
|
58
|
+
|
59
|
+
Or install it yourself as:
|
60
|
+
|
61
|
+
$ gem install mod_10
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
Include the Mod10 module to make the following two methods available
|
66
|
+
- generate_check_digit(value)
|
67
|
+
Which returns an integer value for the mod10 check digit of a string or integer.
|
68
|
+
Note: If the value is 0, then the argument was already mod10 valid.
|
69
|
+
|
70
|
+
- is_mod10?(value)
|
71
|
+
Returns true or false for the tested value is it is or isn't mod10 valid.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it ( https://github.com/[my-github-username]/mod_10/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create a new Pull Request
|
80
|
+
email:
|
81
|
+
- kryptykfysh@kryptykfysh.co.uk
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- ".gitignore"
|
87
|
+
- ".ruby-version"
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/mod_10.rb
|
93
|
+
- lib/mod_10/version.rb
|
94
|
+
- mod_10-0.0.1.gem
|
95
|
+
- mod_10-0.0.2.gem
|
96
|
+
- mod_10.gemspec
|
97
|
+
homepage: https://github.com/kryptykfysh/mod_10
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.4.1
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Generates mod10 check digits and checks if values already are valid mod10.
|
121
|
+
test_files: []
|
122
|
+
has_rdoc:
|