isisbn 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 72d5600b40e28063a0d5e7c4bc86bb81439fdda8135222c0f34954777dcb607d
4
+ data.tar.gz: 9b39ba6dcf189225c7d8c1c5302ed3c19f7e19b052313d7ee96c85a64db07ae7
5
+ SHA512:
6
+ metadata.gz: bc95a48549414eec4fad5c1334823015ffb7310e0c333e013ca5f1e224e493c68a7a9876079a7d6a2e5f746dca9b271c18e91e430eb2cf376ebf6e166a00e6ad
7
+ data.tar.gz: da6b52d82a7a1ed3bcdbff273f7064c267db3efe586e2f155acee9b477a26de2574341851ae4f32e221ae8271cf7fee6e9e428e1b5065cdcfd914002391e24dd
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in isisbn.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Isisbn
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/isisbn`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'isisbn'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install isisbn
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/isisbn.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Isisbn
4
+ VERSION = "0.1.0"
5
+ end
data/lib/isisbn.rb ADDED
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "isisbn/version"
4
+
5
+ module Isisbn
6
+ class Error < StandardError; end
7
+
8
+ # validate ISBN number
9
+ def self.validate(isbn)
10
+ length = isbn.length # get length of isbn number
11
+
12
+ if length == 10 # if length is 10
13
+ validate10(isbn) # validate the isbn number
14
+ elsif length == 13 # if length is 10
15
+ validate13(isbn) # validate the isbn number
16
+ else # others return false
17
+ return false
18
+
19
+ end
20
+
21
+ end
22
+
23
+ # define validate10 to check the isbn number with 10 digits.
24
+ def self.validate10(isbn)
25
+ sum = 0
26
+ for i in 0..9 # loop each digit of the isbn number
27
+ sum = sum + ( isbn[i].to_i * (10-i) ) # sum of the (each digit * position index)
28
+ end
29
+
30
+ if sum % 11 == 0 # if remainer is 0, then it is valid isbn number
31
+ return true
32
+ else
33
+ return false
34
+ end
35
+
36
+ end
37
+
38
+ # define validate13 to check the isbn number with 13 digits
39
+ def self.validate13(isbn)
40
+ sum = 0
41
+ for i in 0..12
42
+ if (13-i) % 2 == 1
43
+ sum = sum + isbn[i].to_i * 1 # odd position, multiply by 1
44
+ else
45
+ sum = sum + isbn[i].to_i * 3 # even position, multiply by 3
46
+ end
47
+ end
48
+
49
+ if sum % 10 == 0 # if remainer is 0, then it is valid isbn number
50
+ return true
51
+ else
52
+ return false
53
+ end
54
+
55
+ end
56
+
57
+ end
data/sig/isisbn.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Isisbn
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isisbn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jiashun-nci
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Validate the ISBN Numbers
14
+ email:
15
+ - 73401615+jiashun-nci@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - README.md
22
+ - Rakefile
23
+ - lib/isisbn.rb
24
+ - lib/isisbn/version.rb
25
+ - sig/isisbn.rbs
26
+ homepage: https://github.com/jiashun-nci/gems
27
+ licenses: []
28
+ metadata:
29
+ allowed_push_host: https://rubygems.org
30
+ homepage_uri: https://github.com/jiashun-nci/gems
31
+ source_code_uri: https://github.com/jiashun-nci/gems
32
+ changelog_uri: https://github.com/jiashun-nci/gems
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.6.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.3.7
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Simply ISBN validator
52
+ test_files: []