isbn-calculator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12e019c48855ba73155f6a66f29be2309577d896336abdc65afbfd2ecf5f6b72
4
+ data.tar.gz: 06e607af348d6a2d021a83940291e2055a52b5437661953732e0db6976c969f0
5
+ SHA512:
6
+ metadata.gz: 651f713a7ea2a9523d4a2515a95951a4240824c58e831e2472774f80b1f6bf3d9c310bf948056d7caef7b46719dfcf2560383e00fb4d5f70c208a637b9a0bd6b
7
+ data.tar.gz: 94af04bac461c1953157d55d80ab1915402596e4f0a87881fee5f5070da330615aee1cf9d12ce870023bce6d74e9b44f6e2848147bb818864362ffb12dc76110
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build isbn-calculator-1.0.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install isbn-calculator-1.0.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install isbn-calculator-1.0.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v1.0.0 and build and push isbn-calculator-1.0.0.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, rbenv: 2.6.4) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, rbenv: 2.6.4) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, rbenv: 2.6.4) [gem]" level="application" />
17
+ </component>
18
+ </module>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.6.4" project-jdk-type="RUBY_SDK" />
7
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/isbn-calculator.iml" filepath="$PROJECT_DIR$/.idea/isbn-calculator.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ isbn-calculator (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (13.0.1)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.2)
16
+ rspec-support (~> 3.9.3)
17
+ rspec-expectations (3.9.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 2.0)
30
+ isbn-calculator!
31
+ rake (>= 12.3.3)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Theo Morra
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # isbn-calculator
2
+
3
+ [![gem](https://img.shields.io/gem/v/isbn-calculator.svg)](https://rubygems.org/gems/isbn-calculator)
4
+
5
+ _A validator for New Zealand tax numbers (IRD)_
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem install isbn-calculator
11
+ ```
12
+ or add `isbn-calculator` to your Gemfile
13
+
14
+ ## Usage
15
+
16
+ Function requires one string parameter:
17
+ * Partial ISBN number (normal or dashed format, e.g. `978014300723`)
18
+ Returns an integer.
19
+
20
+ ```
21
+ require 'isbn-calculator'
22
+ ISBN::Calculator.calculate(000000000000) # 13 digit ISBN (12 digits supplied)
23
+ ```
24
+
25
+ ## Algorithm
26
+
27
+ The algorithm is based on the EAN checksum algorithm.
28
+
29
+ ### ISBN validation - modulus 10 digit check
30
+
31
+ The ISBN number format is a thirteen digit number consisting of the following parts -
32
+
33
+ * A twelve digit base number
34
+ * A trailing check digit
35
+
36
+ ### Check digit validation
37
+
38
+ The following steps are to be performed:
39
+
40
+ * Calculate the check digit
41
+ * To each of the base number’s twelve digits a weight factor is assigned. From left to right these are: 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3.
42
+ * Sum together the products of the weight factors and their associated digits.
43
+ * Divide the sum by 10. If the remainder is 0 then the calculated check digit is 0.
44
+ * If the remainder is not 0 then subtract the remainder from 10, giving the calculated check digit.
45
+
46
+ ## Contributing
47
+
48
+ Pull requests are welcome.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "isbn/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "isbn-calculator"
7
+ spec.version = ISBN::Calculator::VERSION
8
+ spec.license = "MIT"
9
+ spec.authors = ["Theo Morra"]
10
+ spec.email = ["theo@theom.nz"]
11
+
12
+ spec.summary = %q{Calculates the check digit of a partial ISBN}
13
+ spec.homepage = 'https://github.com/td512/isbn-calculator'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", ">= 12.3.3"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
27
+
@@ -0,0 +1,29 @@
1
+ module ISBN
2
+ module Calculator
3
+ WEIGHT = 131313131313.freeze
4
+
5
+ def self.calculate(isbn)
6
+ isbn = (isbn.is_a? Integer) ? isbn : isbn.gsub('-', '').to_i
7
+ return false if ! isbn || ! isbn.to_s.chars.count == 12 || isbn.zero? || isbn.nil?
8
+ checksum = self.weighted_calc(isbn, WEIGHT) % 10
9
+ checksum = checksum.zero? ? checksum : 10 - checksum
10
+
11
+ return checksum
12
+ end
13
+
14
+ def self.weighted_calc(number, weight)
15
+ checksum = 0
16
+
17
+ # if we have 0 after dividing by 10 there is nothing else to do.
18
+ while number > 0
19
+ checksum += (number % 10) * (weight % 10)
20
+
21
+ # discard the digits we've summed up already
22
+ number = number / 10
23
+ weight = weight / 10
24
+ end
25
+
26
+ return checksum
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module ISBN
2
+ module Calculator
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isbn-calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Theo Morra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-13 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - theo@theom.nz
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitattributes"
63
+ - ".idea/.gitignore"
64
+ - ".idea/.rakeTasks"
65
+ - ".idea/inspectionProfiles/Project_Default.xml"
66
+ - ".idea/isbn-calculator.iml"
67
+ - ".idea/misc.xml"
68
+ - ".idea/modules.xml"
69
+ - ".idea/vcs.xml"
70
+ - ".rspec"
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - isbn-calculator.gemspec
77
+ - lib/isbn/calculator.rb
78
+ - lib/isbn/version.rb
79
+ homepage: https://github.com/td512/isbn-calculator
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Calculates the check digit of a partial ISBN
102
+ test_files: []