mod11 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a030b6b482043e7672880786835da88e48bf98b8
4
+ data.tar.gz: f02c78b053b86668bc42c5f9e9edcf8430ce4d4a
5
+ SHA512:
6
+ metadata.gz: fc26f163cc062706db46575dcb357f89e8b2d6d23e48bdd4bf95e45c76f9a56032056d082e7eb9a01ecdb679090ada52e9892d9d54c9469b70461bcfb847a690
7
+ data.tar.gz: b4eaba80f017c5cfc301bb14e85c6daab7284b4ec25ebb8eca2380e212bb6964017d45f036592ce6a42a8d830acc07c8f540dd96e1de90a4dbfb0c0be07ecfb1
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.rubocop.yml
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Stanislav Gorski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Mod11
2
+
3
+ Modulus 11 Self-Check digits
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mod11'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mod11
20
+
21
+ ## Usage
22
+
23
+ ````ruby
24
+ # Initialize with numeric string
25
+ mod = Mod11.new '12312321321'
26
+ => #<Mod11:0x007ffdd316d888 @initial_value="12312321321">
27
+ mod.check_digit
28
+ => 6
29
+ mod.full_value
30
+ => "123123213216"
31
+
32
+ # Or with an integer
33
+ mod = Mod11.new 12312321321
34
+ => #<Mod11:0x007ffdd3145428 @initial_value=12312321321>
35
+ mod.check_digit
36
+ => 6
37
+ mod.full_value
38
+ => "123123213216"
39
+ ````
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/[my-github-username]/mod11/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mod11'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require 'mod11/version'
2
+
3
+ class Mod11
4
+ WEIGHT = [2, 3, 4, 5, 6, 7,
5
+ 2, 3, 4, 5, 6, 7,
6
+ 2, 3, 4, 5, 6, 7]
7
+
8
+ attr_accessor :initial_value
9
+
10
+ def initialize(initial_value)
11
+ @initial_value = initial_value
12
+ end
13
+
14
+ def full_value
15
+ initial_value.to_s + check_digit.to_s
16
+ end
17
+
18
+ def check_digit
19
+ sum = 0
20
+
21
+ initial_value.to_s.reverse.chars.each_with_index do |char, i|
22
+ sum += char.to_i * WEIGHT[i]
23
+ end
24
+
25
+ remainder = sum % 11
26
+
27
+ case remainder
28
+ when 0 then remainder
29
+ when 1 then nil
30
+ else 11 - remainder
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class Mod11
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mod11/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mod11'
8
+ spec.version = Mod11::VERSION
9
+ spec.authors = ['badmanski']
10
+ spec.email = ['stanislav.gorski@gmail.com']
11
+ spec.homepage = 'https://github.com/badmanski/mod11'
12
+
13
+ spec.summary = 'Modulus 11 Self-Check digits'
14
+ spec.description = 'Modulus 11 Self-Check digits'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(/^(test|spec|features)\//)
19
+ end
20
+
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mod11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - badmanski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Modulus 11 Self-Check digits
14
+ email:
15
+ - stanislav.gorski@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bin/console
26
+ - bin/setup
27
+ - lib/mod11.rb
28
+ - lib/mod11/version.rb
29
+ - mod11.gemspec
30
+ homepage: https://github.com/badmanski/mod11
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.5
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Modulus 11 Self-Check digits
54
+ test_files: []