petrarca 0.5.14 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa2df2a6f1e30014fc0e5b291b95376cfda3dc371e9fb15c9ac3923fc91483cc
4
- data.tar.gz: 93535ba910573efe2278e8b5f410154493f7b1b8016b5ec8e6f4803493400fb4
3
+ metadata.gz: f40294feb3dba953df60ffe0e0820ebb3a58ca6cec8cdb083445f91b727d6536
4
+ data.tar.gz: a35e8059829bdeb690d286c90aedee21538a2b043e8a5df93f6316544db0ebb8
5
5
  SHA512:
6
- metadata.gz: c706a41152e219875d9f877c9bd4773e448cc6cc978653e46e866abf4e113594b7c1c5c74a9a0e914be88c6ac159af3d82bf5cfd5d3e92f1b006d6300df1802d
7
- data.tar.gz: 72467858ec4e902c05c024d03d3898e415c315083e005382081f02767099f9c9f16934582d9db8255253f6207cac80ae8f2ecd616243db9df62db4652ae6fcbd
6
+ metadata.gz: 8c7de20465a052e43febf9e70f7f1c091271705c547e0d657f640f63d0ed85aee75c4505b0cd0d6afcb4ba0919385390131e62a7b3db88ffa03d6eef41e053bc
7
+ data.tar.gz: f650a186dab622cf9b7835a0c52b708b6d3c45fa5118fdd935dd6a98f50781564bb8c9b3b4236733411587cc661ef6c66fff21140fdb7cbb4d4880b72b638894
data/README.md CHANGED
@@ -5,14 +5,15 @@ This library Petrarca provides some utility functions to manipulate ISBN numbers
5
5
  - Validation
6
6
  - Calculate check digit
7
7
  - Mutual conversion of ISBN-13 and ISBN-10
8
- - Hyphenation
8
+ - Hyphenation / Dehyphenation
9
+ - Split to a array that includes ISBN segments
9
10
 
10
11
  All functions support both ISBN-13 and ISBN-10.
11
12
 
12
13
  All ranges of registration groups and registrants are supported.
13
14
  Those depends on 'RangeMessage.xml' file, downloaded from [International ISBN Agency](https://www.isbn-international.org/range_file_generation).
14
15
 
15
- NOTE: Updated range files to latest version on August 5, 2023.
16
+ NOTE: Updated range files to latest version on December 30, 2023.
16
17
 
17
18
  ## Installation
18
19
 
@@ -44,10 +45,14 @@ Or install it yourself as:
44
45
  => "978-4-8156-0644-2"
45
46
  irb(main):006:0> Petrarca.hyphenate("9784815606442")
46
47
  => "978-4-8156-0644-2"
48
+ irb(main):007:0> Petrarca.dehyphenate("978-4-8156-0644-2")
49
+ => "9784815605442"
50
+ irb(main):008:0> Petrarca.split("9784815606442")
51
+ => ["978", "4", "8156", "0644", "2"]
47
52
 
48
- Accept Integer as ISBN, only if no `-` and `X` including.
53
+ `Petrarca.dehyphenate` and `Petrarca.split` are new in v0.6.0.
49
54
 
50
- New in v0.5.0.
55
+ Accept Integer as ISBN, only if no `-` and `X` including. (New in v0.5.0)
51
56
 
52
57
  irb(main):001:0> require 'petrarca'
53
58
  => true
@@ -1,16 +1,16 @@
1
1
  # Generated from RangeMessage.xml file, downloaded from https://www.isbn-international.org/range_file_generation.
2
2
  #
3
3
  # International ISBN Agency
4
- # Sat, 5 Aug 2023 03:08:36 BST
4
+ # Sat, 30 Dec 2023 23:48:36 GMT
5
5
  #
6
6
  # English language
7
- 978-0:00-19,200-227,2280-2289,229-368,3690-3699,370-638,6390-6397,6398000-6399999,640-644,6450000-6459999,646-647,6480000-6489999,649-654,6550-6559,656-699,7000-8499,85000-89999,900000-949999,9500000-9999999
7
+ 978-0:00-19,200-227,2280-2289,229-368,3690-3699,370-638,6390-6397,6398000-6399999,640-644,6450000-6459999,646-647,6480000-6489999,649-654,6550-6559,656-699,7000-8499,85000-89999,900000-900370,9003710-9003719,900372-949999,9500000-9999999
8
8
  # English language
9
- 978-1:000-009,01-02,030-034,0350-0399,040-049,05-06,0700-0999,100-397,3980-5499,55000-64999,6500-6799,68000-68599,6860-7139,714-716,7170-7319,7320000-7399999,74000-77499,7750000-7753999,77540-77639,7764000-7764999,77650-77699,7770000-7782999,77830-78999,7900-7999,80000-80049,80050-80499,80500-83799,8380000-8384999,83850-86719,8672-8675,86760-86979,869800-915999,9160000-9165059,916506-916869,9168700-9169079,916908-919599,9196000-9196549,919655-972999,9730-9877,987800-991149,9911500-9911999,991200-998989,9989900-9999999
9
+ 978-1:000-009,01-02,030-034,0350-0399,040-049,05-05,0670000-0699999,0700-0999,100-397,3980-5499,55000-64999,6500-6799,68000-68599,6860-7139,714-716,7170-7319,7320000-7399999,74000-76199,7620-7634,7635000-7649999,76500-77499,7750000-7753999,77540-77639,7764000-7764999,77650-77699,7770000-7782999,77830-78999,7900-7999,80000-80049,80050-80499,80500-83799,8380000-8384999,83850-86719,8672-8675,86760-86979,869800-915999,9160000-9165059,916506-916869,9168700-9169079,916908-919599,9196000-9196549,919655-972999,9730-9877,987800-991149,9911500-9911999,991200-998989,9989900-9999999
10
10
  # French language
11
11
  978-2:00-19,200-349,35000-39999,400-486,487000-494999,495-495,4960-4966,49670-49699,497-527,5280-5299,530-699,7000-8399,84000-89999,900000-919799,91980-91980,919810-919942,9199430-9199689,919969-949999,9500000-9999999
12
12
  # German language
13
- 978-3:00-02,030-033,0340-0369,03700-03999,04-19,200-699,7000-8499,85000-89999,900000-949999,9500000-9539999,95400-96999,9700000-9849999,98500-99999
13
+ 978-3:00-02,030-033,0340-0369,03700-03999,04-19,200-389,39-39,400-688,68900-69499,6950-8499,85000-89999,900000-949999,9500000-9539999,95400-96999,9700000-9849999,98500-99999
14
14
  # Japan
15
15
  978-4:00-19,200-699,7000-8499,85000-89999,900000-949999,9500000-9999999
16
16
  # former U.S.S.R
@@ -25,12 +25,12 @@
25
25
  978-603:00-04,05-49,500-799,8000-8999,90000-99999
26
26
  # Vietnam
27
27
  978-604:0-2,300-399,40-46,470-497,4980-4999,50-89,900-979,9800-9999
28
- # Turkey
28
+ # Türkiye
29
29
  978-605:00-02,030-039,04-05,06000-06999,07-09,100-199,2000-2399,240-399,4000-5999,60000-74999,7500-7999,80000-89999,9000-9999
30
30
  # Romania
31
31
  978-606:000-099,10-49,500-799,8000-9099,910-919,92000-95999,9600-9749,975-999
32
32
  # Mexico
33
- 978-607:00-39,400-592,59300-59999,600-749,7500-9499,95000-99999
33
+ 978-607:00-39,400-588,5890-5929,59300-59999,600-694,69500-69999,700-749,7500-9499,95000-99999
34
34
  # North Macedonia
35
35
  978-608:0-0,10-19,200-449,4500-6499,65000-69999,7-9
36
36
  # Lithuania
@@ -60,11 +60,11 @@
60
60
  # Iran
61
61
  978-622:00-10,200-424,5200-8499,90000-99999
62
62
  # Indonesia
63
- 978-623:00-09,130-499,5250-8799,88000-99999
63
+ 978-623:00-09,110-499,5250-8799,88000-99999
64
64
  # Sri Lanka
65
- 978-624:00-04,200-249,5000-6449,94500-99999
66
- # Turkey
67
- 978-625:00-00,365-442,44300-44499,445-449,6350-7793,77940-77949,7795-8499,99000-99999
65
+ 978-624:00-04,200-249,5000-6699,93000-99999
66
+ # Türkiye
67
+ 978-625:00-01,365-442,44300-44499,445-449,6000-7793,77940-77949,7795-8499,94000-99999
68
68
  # Taiwan
69
69
  978-626:00-04,300-499,7000-7999,95000-99999
70
70
  # Pakistan
@@ -110,7 +110,7 @@
110
110
  # India
111
111
  978-93:00-09,100-499,5000-7999,80000-95999,960000-999999
112
112
  # Netherlands
113
- 978-94:000-599,6000-8999,90000-99999
113
+ 978-94:000-599,6000-6387,638800-638809,63881-63881,638820-638839,63884-63885,638860-638869,63887-63889,6389-6395,639600-639609,63961-63962,639630-639639,63964-63964,639650-639659,63966-63969,6397-6399,640000-640009,64001-64004,640050-640059,64006-64006,640070-640089,64009-64009,6401-6406,640700-640739,64074-64074,640750-640759,64076-64077,640780-640799,6408-6419,64200-64201,642020-642029,64203-64203,642040-642049,64205-64206,642070-642079,64208-64208,642090-642099,6421-6432,64330-64331,643320-643329,64333-64333,643340-643359,64336-64336,643370-643379,64338-64339,6434-6435,643600-643609,64361-64363,643640-643659,64366-64366,643670-643679,64368-64369,6437-6443,644400-644409,64441-64441,644420-644429,64443-64443,644440-644449,64445-64446,644470-644489,64449-64449,6445-6450,64510-64512,645130-645139,64514-64515,645160-645199,6452-6458,645900-645909,64591-64592,645930-645949,64595-64596,645970-645989,64599-64599,6460-6465,646600-646609,64661-64662,646630-646659,64666-64666,646670-646689,64669-64669,6467-6474,64750-64751,647520-647539,64754-64754,647550-647559,64756-64757,647580-647589,64759-64759,6476-6476,647700-647708,64771-64771,647800-647809,64781-64781,647820-647829,64783-64786,647870-647879,64788-64789,6479-8999,90000-99999
114
114
  # Argentina
115
115
  978-950:00-49,500-899,9000-9899,99000-99999
116
116
  # Finland
@@ -118,7 +118,7 @@
118
118
  # Finland
119
119
  978-952:00-19,200-499,5000-5999,60-64,65000-65999,6600-6699,67000-69999,7000-7999,80-94,9500-9899,99000-99999
120
120
  # Croatia
121
- 978-953:0-0,10-14,150-479,48000-49999,500-500,50100-50999,51-54,55000-59999,6000-9499,95000-99999
121
+ 978-953:0-0,10-14,150-459,46000-49999,500-500,50100-50999,51-54,55000-59999,6000-9499,95000-99999
122
122
  # Bulgaria
123
123
  978-954:00-28,2900-2999,300-799,8000-8999,90000-92999,9300-9999
124
124
  # Sri Lanka
@@ -161,7 +161,7 @@
161
161
  978-973:0-0,100-169,1700-1999,20-54,550-759,7600-8499,85000-88999,8900-9499,95000-99999
162
162
  # Thailand
163
163
  978-974:00-19,200-699,7000-8499,85000-89999,90000-94999,9500-9999
164
- # Turkey
164
+ # Türkiye
165
165
  978-975:00000-01999,02-23,2400-2499,250-599,6000-9199,92000-98999,990-999
166
166
  # Caribbean Community
167
167
  978-976:0-3,40-59,600-799,8000-9499,95000-99999
@@ -174,7 +174,7 @@
174
174
  # Venezuela
175
175
  978-980:00-19,200-599,6000-9999
176
176
  # Singapore
177
- 978-981:00-16,17000-17999,18-19,200-299,3000-3099,310-399,4000-9499,99-99
177
+ 978-981:00-16,17000-17999,18-19,200-299,3000-3099,310-399,4000-9499,97-99
178
178
  # South Pacific
179
179
  978-982:00-09,100-699,70-89,9000-9799,98000-99999
180
180
  # Malaysia
@@ -192,7 +192,7 @@
192
192
  # Portugal
193
193
  978-989:0-1,20-34,35000-36999,37-52,53000-54999,550-799,8000-9499,95000-99999
194
194
  # Uzbekistan
195
- 978-9910:730-749,9650-9999
195
+ 978-9910:01-08,710-799,9250-9999
196
196
  # Montenegro
197
197
  978-9911:20-24,550-749
198
198
  # Tanzania
@@ -200,13 +200,13 @@
200
200
  # Uganda
201
201
  978-9913:00-07,600-699,9550-9999
202
202
  # Kenya
203
- 978-9914:40-52,700-774,9600-9999
203
+ 978-9914:40-55,700-774,9600-9999
204
204
  # Uruguay
205
205
  978-9915:40-59,650-799,9300-9999
206
206
  # Estonia
207
- 978-9916:0-0,10-39,4-5,600-799,80-84,850-899,9250-9999
207
+ 978-9916:0-0,10-39,4-5,600-799,80-91,9250-9999
208
208
  # Bolivia
209
- 978-9917:0-0,30-34,600-699,9800-9999
209
+ 978-9917:0-0,30-34,600-699,9700-9999
210
210
  # Malta
211
211
  978-9918:0-0,20-29,600-799,9500-9999
212
212
  # Mongolia
@@ -218,7 +218,7 @@
218
218
  # Iraq
219
219
  978-9922:20-29,600-799,8500-9999
220
220
  # Jordan
221
- 978-9923:0-0,10-59,700-899,9400-9999
221
+ 978-9923:0-0,10-69,700-899,9400-9999
222
222
  # Cambodia
223
223
  978-9924:30-39,500-649,9000-9999
224
224
  # Cyprus
@@ -238,7 +238,7 @@
238
238
  # Lao People's Democratic Republic
239
239
  978-9932:00-39,400-849,8500-9999
240
240
  # Syria
241
- 978-9933:0-0,10-39,400-899,9000-9999
241
+ 978-9933:0-0,10-39,400-869,87-89,9000-9999
242
242
  # Latvia
243
243
  978-9934:0-0,10-49,500-799,8000-9999
244
244
  # Iceland
@@ -250,7 +250,7 @@
250
250
  # Tunisia
251
251
  978-9938:00-79,800-949,9500-9749,975-990,9910-9999
252
252
  # Armenia
253
- 978-9939:0-4,50-79,800-899,9000-9599,960-979,98-99
253
+ 978-9939:0-3,40-79,800-899,9000-9599,960-979,98-99
254
254
  # Montenegro
255
255
  978-9940:0-1,20-49,500-839,84-86,8700-9999
256
256
  # Georgia
@@ -259,7 +259,7 @@
259
259
  978-9942:00-59,600-699,7000-7499,750-849,8500-8999,900-984,9850-9999
260
260
  # Uzbekistan
261
261
  978-9943:00-29,300-399,4000-9749,975-999
262
- # Turkey
262
+ # Türkiye
263
263
  978-9944:0000-0999,100-499,5000-5999,60-69,700-799,80-89,900-999
264
264
  # Dominican Republic
265
265
  978-9945:00-00,010-079,08-39,400-569,57-57,580-799,80-80,810-849,8500-9999
@@ -500,7 +500,7 @@
500
500
  # Tajikistan
501
501
  978-99975:0-2,300-399,40-79,800-999
502
502
  # Srpska, Republic of
503
- 978-99976:0-0,10-15,160-199,20-59,600-819,82-89,900-999
503
+ 978-99976:00-03,075-099,10-15,160-199,20-59,600-819,82-89,900-999
504
504
  # Rwanda
505
505
  978-99977:0-1,40-69,700-799,975-999
506
506
  # Mongolia
@@ -508,13 +508,13 @@
508
508
  # Honduras
509
509
  978-99979:0-3,40-79,800-999
510
510
  # Bhutan
511
- 978-99980:0-0,30-59,750-999
511
+ 978-99980:0-0,30-64,700-999
512
512
  # Macau
513
- 978-99981:0-1,200-219,24-74,750-999
513
+ 978-99981:0-0,140-149,15-19,200-219,22-74,750-999
514
514
  # Benin
515
515
  978-99982:0-1,50-68,900-999
516
516
  # El Salvador
517
- 978-99983:0-0,50-69,950-999
517
+ 978-99983:0-0,35-69,900-999
518
518
  # Brunei Darussalam
519
519
  978-99984:0-0,50-69,950-999
520
520
  # Tajikistan
@@ -532,12 +532,14 @@
532
532
  # Oman
533
533
  978-99992:0-1,50-64,950-999
534
534
  # Mauritius
535
- 978-99993:0-0,50-54,980-999
535
+ 978-99993:0-1,50-54,980-999
536
+ # Haiti
537
+ 978-99994:0-0,50-52,985-999
536
538
  # France
537
539
  979-10:00-19,200-699,7000-8999,90000-97599,976000-999999
538
540
  # Korea, Republic
539
541
  979-11:00-24,250-549,5500-8499,85000-94999,950000-999999
540
542
  # Italy
541
- 979-12:200-299,5450-5999,80000-84999
543
+ 979-12:200-299,5450-5999,80000-84999,985000-999999
542
544
  # United States
543
- 979-8:200-229,3500-3999,4000-8499,8500-8849,88500-89999,9850000-9899999
545
+ 979-8:200-229,3200-3499,3500-8849,88500-89999,90000-90999,9850000-9899999,9900000-9929999
@@ -1,7 +1,7 @@
1
1
  # Generated from RangeMessage.xml file, downloaded from https://www.isbn-international.org/range_file_generation.
2
2
  #
3
3
  # International ISBN Agency
4
- # Sat, 5 Aug 2023 03:08:36 BST
4
+ # Sat, 30 Dec 2023 23:48:36 GMT
5
5
  #
6
6
  # International ISBN Agency
7
7
  978:0-5,600-649,65-65,7-7,80-94,950-989,9900-9989,99900-99999
@@ -8,7 +8,7 @@ module Petrarca
8
8
  extend self
9
9
 
10
10
  def split(isbn)
11
- isbn = isbn.to_s.delete("-")
11
+ isbn = Petrarca.dehyphenate(isbn)
12
12
  ean_prefix = isbn[0, 3]
13
13
  unless ean_prefix == "978" || ean_prefix == "979"
14
14
  raise InvalidEANPrefixError.new("Invalid EAN prefix: #{ean_prefix}")
@@ -20,12 +20,12 @@ module Petrarca
20
20
  end
21
21
 
22
22
  def correct_format?(isbn)
23
- isbn = isbn.to_s.delete("-")
23
+ isbn = dehyphenate(isbn)
24
24
  !!(/\A\d{9}[0-9X]\z/ =~ isbn)
25
25
  end
26
26
 
27
27
  def calc_check_digit(isbn)
28
- nums = isbn.to_s.delete("-").split("")[0, 9].map{|x| x.to_i }
28
+ nums = dehyphenate(isbn).split("")[0, 9].map{|x| x.to_i }
29
29
  sum = nums.zip((2..10).to_a.reverse).map{|x, y| x * y }.inject(:+)
30
30
  check_digit = 11 - (sum % 11)
31
31
  case check_digit
@@ -37,9 +37,17 @@ module Petrarca
37
37
  check_digit.to_s
38
38
  end
39
39
  end
40
+
41
+ def dehyphenate(isbn)
42
+ Petrarca.dehyphenate(isbn)
43
+ end
40
44
 
41
45
  def hyphenate(isbn)
42
- Helpers.split("978" + isbn.to_s).drop(1).join("-")
46
+ split(isbn).join("-")
47
+ end
48
+
49
+ def split(isbn)
50
+ Helpers.split("978" + isbn.to_s).drop(1)
43
51
  end
44
52
 
45
53
  end
@@ -20,19 +20,27 @@ module Petrarca
20
20
  end
21
21
 
22
22
  def correct_format?(isbn)
23
- isbn = isbn.to_s.delete("-")
23
+ isbn = dehyphenate(isbn)
24
24
  !!(/\A97[89]\d{9}\d\z/ =~ isbn)
25
25
  end
26
26
 
27
27
  def calc_check_digit(isbn)
28
- nums = isbn.to_s.delete("-").split("")[0, 12].map{|x| x.to_i }
28
+ nums = dehyphenate(isbn).split("")[0, 12].map{|x| x.to_i }
29
29
  sum = nums.zip([1, 3] * 6).map{|x, y| x * y }.inject(:+)
30
30
  check_digit = 10 - (sum % 10)
31
31
  check_digit == 10 ? "0" : check_digit.to_s
32
32
  end
33
33
 
34
+ def dehyphenate(isbn)
35
+ Petrarca.dehyphenate(isbn)
36
+ end
37
+
34
38
  def hyphenate(isbn)
35
- Helpers.split(isbn).join("-")
39
+ split(isbn).join("-")
40
+ end
41
+
42
+ def split(isbn)
43
+ Helpers.split(isbn)
36
44
  end
37
45
 
38
46
  end
@@ -1,3 +1,3 @@
1
1
  module Petrarca
2
- VERSION = "0.5.14"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/petrarca.rb CHANGED
@@ -15,7 +15,7 @@ module Petrarca
15
15
  extend self
16
16
 
17
17
  def valid?(isbn)
18
- case isbn.to_s.delete("-").size
18
+ case dehyphenate(isbn).size
19
19
  when 13
20
20
  ISBN13.valid?(isbn)
21
21
  when 10
@@ -26,7 +26,7 @@ module Petrarca
26
26
  end
27
27
 
28
28
  def correct_format?(isbn)
29
- case isbn.to_s.delete("-").size
29
+ case dehyphenate(isbn).size
30
30
  when 13
31
31
  ISBN13.correct_format?(isbn)
32
32
  when 10
@@ -37,7 +37,7 @@ module Petrarca
37
37
  end
38
38
 
39
39
  def calc_check_digit(isbn)
40
- isbn = isbn.to_s.delete("-")
40
+ isbn = dehyphenate(isbn)
41
41
  case isbn.size
42
42
  when 12, 13
43
43
  ISBN13.calc_check_digit(isbn)
@@ -48,6 +48,10 @@ module Petrarca
48
48
  end
49
49
  end
50
50
 
51
+ def dehyphenate(isbn)
52
+ isbn.to_s.delete("-")
53
+ end
54
+
51
55
  def hyphenate(isbn)
52
56
  isbn = isbn.to_s
53
57
  case isbn.size
@@ -58,13 +62,23 @@ module Petrarca
58
62
  end
59
63
  end
60
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
+
61
75
  def to_10(isbn13)
62
- s = isbn13.to_s.delete("-")[3, 9]
76
+ s = dehyphenate(isbn13)[3, 9]
63
77
  ISBN10.hyphenate(s + ISBN10.calc_check_digit(s))
64
78
  end
65
79
 
66
80
  def to_13(isbn10)
67
- s = "978" + isbn10.to_s.delete("-")[0, 9]
81
+ s = "978" + dehyphenate(isbn10)[0, 9]
68
82
  ISBN13.hyphenate(s + ISBN13.calc_check_digit(s))
69
83
  end
70
84
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petrarca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takatoh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-05 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler