petrarca 0.6.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/petrarca.rb CHANGED
@@ -1,85 +1,85 @@
1
- require "petrarca/version"
2
- require "petrarca/isbn13"
3
- require "petrarca/isbn10"
4
- require "petrarca/helpers"
5
-
6
-
7
- module Petrarca
8
- class Error < StandardError; end
9
- class IncorrectFormatError < StandardError; end
10
-
11
- data_dir = __dir__ + "/../data"
12
- REGISTRATION_GROUP_RANGES = Helpers.load_ranges("#{data_dir}/registration_group_ranges.txt")
13
- REGISTRANT_RANGES = Helpers.load_ranges("#{data_dir}/registrant_ranges.txt")
14
-
15
- extend self
16
-
17
- def valid?(isbn)
18
- case dehyphenate(isbn).size
19
- when 13
20
- ISBN13.valid?(isbn)
21
- when 10
22
- ISBN10.valid?(isbn)
23
- else
24
- false
25
- end
26
- end
27
-
28
- def correct_format?(isbn)
29
- case dehyphenate(isbn).size
30
- when 13
31
- ISBN13.correct_format?(isbn)
32
- when 10
33
- ISBN10.correct_format?(isbn)
34
- else
35
- false
36
- end
37
- end
38
-
39
- def calc_check_digit(isbn)
40
- isbn = dehyphenate(isbn)
41
- case isbn.size
42
- when 12, 13
43
- ISBN13.calc_check_digit(isbn)
44
- when 9, 10
45
- ISBN10.calc_check_digit(isbn)
46
- else
47
- raise IncorrectFormatError
48
- end
49
- end
50
-
51
- def dehyphenate(isbn)
52
- isbn.to_s.delete("-")
53
- end
54
-
55
- def hyphenate(isbn)
56
- isbn = isbn.to_s
57
- case isbn.size
58
- when 13
59
- ISBN13.hyphenate(isbn)
60
- when 10
61
- ISBN10.hyphenate(isbn)
62
- end
63
- end
64
-
65
- def split(isbn)
66
- isbn = isbn.to_s
67
- case isbn.size
68
- when 13
69
- ISBN13.split(isbn)
70
- when 10
71
- ISBN10.split(isbn)
72
- end
73
- end
74
-
75
- def to_10(isbn13)
76
- s = dehyphenate(isbn13)[3, 9]
77
- ISBN10.hyphenate(s + ISBN10.calc_check_digit(s))
78
- end
79
-
80
- def to_13(isbn10)
81
- s = "978" + dehyphenate(isbn10)[0, 9]
82
- ISBN13.hyphenate(s + ISBN13.calc_check_digit(s))
83
- end
84
-
85
- end
1
+ require "petrarca/version"
2
+ require "petrarca/isbn13"
3
+ require "petrarca/isbn10"
4
+ require "petrarca/helpers"
5
+ require "isbnranges"
6
+
7
+
8
+ module Petrarca
9
+ class Error < StandardError; end
10
+ class IncorrectFormatError < StandardError; end
11
+
12
+ REGISTRATION_GROUP_RANGES = ISBNRanges::REGISTRATION_GROUP_RANGES
13
+ REGISTRANT_RANGES = ISBNRanges::REGISTRANT_RANGES
14
+
15
+ extend self
16
+
17
+ def valid?(isbn)
18
+ case dehyphenate(isbn).size
19
+ when 13
20
+ ISBN13.valid?(isbn)
21
+ when 10
22
+ ISBN10.valid?(isbn)
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ def correct_format?(isbn)
29
+ case dehyphenate(isbn).size
30
+ when 13
31
+ ISBN13.correct_format?(isbn)
32
+ when 10
33
+ ISBN10.correct_format?(isbn)
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ def calc_check_digit(isbn)
40
+ isbn = dehyphenate(isbn)
41
+ case isbn.size
42
+ when 12, 13
43
+ ISBN13.calc_check_digit(isbn)
44
+ when 9, 10
45
+ ISBN10.calc_check_digit(isbn)
46
+ else
47
+ raise IncorrectFormatError
48
+ end
49
+ end
50
+
51
+ def dehyphenate(isbn)
52
+ isbn.to_s.delete("-")
53
+ end
54
+
55
+ def hyphenate(isbn)
56
+ isbn = isbn.to_s
57
+ case isbn.size
58
+ when 13
59
+ ISBN13.hyphenate(isbn)
60
+ when 10
61
+ ISBN10.hyphenate(isbn)
62
+ end
63
+ end
64
+
65
+ def split(isbn)
66
+ isbn = isbn.to_s
67
+ case isbn.size
68
+ when 13
69
+ ISBN13.split(isbn)
70
+ when 10
71
+ ISBN10.split(isbn)
72
+ end
73
+ end
74
+
75
+ def to_10(isbn13)
76
+ s = dehyphenate(isbn13)[3, 9]
77
+ ISBN10.hyphenate(s + ISBN10.calc_check_digit(s))
78
+ end
79
+
80
+ def to_13(isbn10)
81
+ s = "978" + dehyphenate(isbn10)[0, 9]
82
+ ISBN13.hyphenate(s + ISBN13.calc_check_digit(s))
83
+ end
84
+
85
+ end
data/petrarca.gemspec CHANGED
@@ -1,44 +1,43 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "petrarca/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "petrarca"
8
- spec.version = Petrarca::VERSION
9
- spec.authors = ["takatoh"]
10
- spec.email = ["takatoh.m@gmail.com"]
11
-
12
- spec.summary = %q{Manipulate ISBN numbers.}
13
- spec.description = %q{Library to manipulate ISBN numbers for Ruby.}
14
- spec.homepage = "https://github.com/takatoh/Petrarca"
15
-
16
- spec.licenses = ["MIT"]
17
-
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
- # if spec.respond_to?(:metadata)
21
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22
- #
23
- # spec.metadata["homepage_uri"] = spec.homepage
24
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
25
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
26
- # else
27
- # raise "RubyGems 2.0 or newer is required to protect against " \
28
- # "public gem pushes."
29
- # end
30
-
31
- # Specify which files should be added to the gem when it is released.
32
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
- end
36
- spec.bindir = "exe"
37
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
- spec.require_paths = ["lib"]
39
-
40
- spec.add_development_dependency "bundler", "~> 2.0"
41
- spec.add_development_dependency "rake", "~> 10.0"
42
- spec.add_development_dependency "rspec", ">= 3.0.0"
43
- spec.add_development_dependency "nokogiri"
44
- end
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "petrarca/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "petrarca"
8
+ spec.version = Petrarca::VERSION
9
+ spec.authors = ["takatoh"]
10
+ spec.email = ["takatoh.m@gmail.com"]
11
+
12
+ spec.summary = %q{Manipulate ISBN numbers.}
13
+ spec.description = %q{Library to manipulate ISBN numbers for Ruby.}
14
+ spec.homepage = "https://github.com/takatoh/Petrarca"
15
+
16
+ spec.licenses = ["MIT"]
17
+
18
+ spec.required_ruby_version = ">= 3.0.0"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
24
+ #
25
+ # spec.metadata["homepage_uri"] = spec.homepage
26
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
27
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
28
+ # else
29
+ # raise "RubyGems 2.0 or newer is required to protect against " \
30
+ # "public gem pushes."
31
+ # end
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
36
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
37
+ end
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+
42
+ spec.add_dependency "isbnranges"
43
+ end
metadata CHANGED
@@ -1,65 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petrarca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takatoh
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
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: '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
- - !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.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.0
55
- - !ruby/object:Gem::Dependency
56
- name: nokogiri
14
+ name: isbnranges
57
15
  requirement: !ruby/object:Gem::Requirement
58
16
  requirements:
59
17
  - - ">="
60
18
  - !ruby/object:Gem::Version
61
19
  version: '0'
62
- type: :development
20
+ type: :runtime
63
21
  prerelease: false
64
22
  version_requirements: !ruby/object:Gem::Requirement
65
23
  requirements:
@@ -81,20 +39,17 @@ files:
81
39
  - Rakefile
82
40
  - bin/console
83
41
  - bin/setup
84
- - data/registrant_ranges.txt
85
- - data/registration_group_ranges.txt
86
42
  - lib/petrarca.rb
87
43
  - lib/petrarca/helpers.rb
88
44
  - lib/petrarca/isbn10.rb
89
45
  - lib/petrarca/isbn13.rb
90
46
  - lib/petrarca/version.rb
91
47
  - petrarca.gemspec
92
- - scripts/generate_range_files.rb
93
48
  homepage: https://github.com/takatoh/Petrarca
94
49
  licenses:
95
50
  - MIT
96
51
  metadata: {}
97
- post_install_message:
52
+ post_install_message:
98
53
  rdoc_options: []
99
54
  require_paths:
100
55
  - lib
@@ -102,15 +57,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
57
  requirements:
103
58
  - - ">="
104
59
  - !ruby/object:Gem::Version
105
- version: '0'
60
+ version: 3.0.0
106
61
  required_rubygems_version: !ruby/object:Gem::Requirement
107
62
  requirements:
108
63
  - - ">="
109
64
  - !ruby/object:Gem::Version
110
65
  version: '0'
111
66
  requirements: []
112
- rubygems_version: 3.3.26
113
- signing_key:
67
+ rubygems_version: 3.5.9
68
+ signing_key:
114
69
  specification_version: 4
115
70
  summary: Manipulate ISBN numbers.
116
71
  test_files: []