bookisbn 0.1.0 → 0.5.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 +4 -4
- data/README.md +10 -16
- data/lib/bookisbn.rb +64 -3
- data/lib/bookisbn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f7582fb853eb4d82e54ee93176c671ef5dd6ea97b8be445af7f1ebb2b573f3a
|
|
4
|
+
data.tar.gz: 2b4c905d15ee77a8d6b530c1adb0c4330f9f0c6e62bc6c8fff30973b95351345
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce3bc1bb5f190dcb05b5a27842197b98e63d02c178528fc538c3b5d5be5367d9ce34eba286ed4cf4c49f25bef41b53ad7bf0a0882d046811ec04f740cd504369
|
|
7
|
+
data.tar.gz: b7f20a448cc93c0ec9ddf6cc95a73840a7491a4a4d15d1997b91e08b93d5d718244feed77e2981384d4ed954948a22f1225701fe5e073955c04af758fbf7ffd8
|
data/README.md
CHANGED
|
@@ -29,24 +29,18 @@ Or install it yourself as:
|
|
|
29
29
|
# check ISBN
|
|
30
30
|
@isbn.check?
|
|
31
31
|
|
|
32
|
-
@isbn.ean_ucc
|
|
33
|
-
@isbn.group
|
|
34
|
-
@isbn.publisher
|
|
35
|
-
@isbn.title
|
|
36
|
-
@isbn.check_digit
|
|
37
|
-
|
|
38
|
-
@isbn.thirteen
|
|
39
|
-
@isbn.thirteen(" ")
|
|
40
|
-
@isbn.ten
|
|
41
|
-
@isbn.ten(" ")
|
|
32
|
+
@isbn.ean_ucc # return ISBN EAN UCC
|
|
33
|
+
@isbn.group # return ISBN Group id
|
|
34
|
+
@isbn.publisher # return ISBN publisher code
|
|
35
|
+
@isbn.title # return ISBN publisher book title order
|
|
36
|
+
@isbn.check_digit # return ISBN check digit
|
|
37
|
+
|
|
38
|
+
@isbn.thirteen # generate ISBN with 13 digits and join with -
|
|
39
|
+
@isbn.thirteen(" ") # generate ISBN with 13 digits and join with space
|
|
40
|
+
@isbn.ten # generate ISBN with 10 digitsand join with -
|
|
41
|
+
@isbn.ten(" ") # generate ISBN with 10 digitsand join with space
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
## Development
|
|
45
|
-
|
|
46
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
47
|
-
|
|
48
|
-
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
49
|
-
|
|
50
44
|
## Contributing
|
|
51
45
|
|
|
52
46
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hfl/bookisbn. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/bookisbn.rb
CHANGED
|
@@ -108,7 +108,9 @@ module Bookisbn
|
|
|
108
108
|
sum += @isbn[i].to_i * 3
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
|
-
if
|
|
111
|
+
if sum%10 == 0 and @isbn[12].to_i == 0
|
|
112
|
+
return true
|
|
113
|
+
elsif 10 - sum%10 == @isbn[12].to_i
|
|
112
114
|
return true
|
|
113
115
|
else
|
|
114
116
|
return false
|
|
@@ -151,11 +153,70 @@ module Bookisbn
|
|
|
151
153
|
end
|
|
152
154
|
|
|
153
155
|
def thirteen(joiner="-")
|
|
154
|
-
|
|
156
|
+
|
|
157
|
+
# export 13 with different style
|
|
158
|
+
if @isbn.length == 13
|
|
159
|
+
[@ean_ucc, @group, @publisher, @title, @check_digit].join(joiner)
|
|
160
|
+
|
|
161
|
+
# convert 10 to 13
|
|
162
|
+
elsif @isbn.length == 10
|
|
163
|
+
sum = 0
|
|
164
|
+
new_isbn = "978" + @isbn
|
|
165
|
+
new_check_digit = 0
|
|
166
|
+
|
|
167
|
+
for i in 0..11
|
|
168
|
+
if new_isbn[i].to_i.odd?
|
|
169
|
+
sum += new_isbn[i].to_i * 1
|
|
170
|
+
else
|
|
171
|
+
sum += new_isbn[i].to_i * 3
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if sum%10 == 0
|
|
176
|
+
new_check_digit = 0
|
|
177
|
+
else
|
|
178
|
+
new_check_digit = 10 - sum%10
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
["978", @group, @publisher, @title, new_check_digit].join(joiner)
|
|
183
|
+
else
|
|
184
|
+
return false
|
|
185
|
+
end
|
|
186
|
+
|
|
155
187
|
end
|
|
156
188
|
|
|
157
189
|
def ten(joiner="-")
|
|
158
|
-
|
|
190
|
+
|
|
191
|
+
# import 10, export 10
|
|
192
|
+
if @isbn.length == 10
|
|
193
|
+
[@group, @publisher, @title, @check_digit].join(joiner)
|
|
194
|
+
|
|
195
|
+
# import 13, export 10
|
|
196
|
+
elsif @isbn.length == 13
|
|
197
|
+
sum = 0
|
|
198
|
+
new_check_digit = ""
|
|
199
|
+
|
|
200
|
+
for i in 3..11
|
|
201
|
+
sum += @isbn[i].to_i * (10 - i)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
cd = 11 - sum%11
|
|
205
|
+
|
|
206
|
+
case cd
|
|
207
|
+
|
|
208
|
+
when 10
|
|
209
|
+
new_check_digit = "X"
|
|
210
|
+
when 11
|
|
211
|
+
new_check_digit = "0"
|
|
212
|
+
else
|
|
213
|
+
new_check_digit = cd.to_s
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
[@group, @publisher, @title, new_check_digit].join(joiner)
|
|
217
|
+
else
|
|
218
|
+
return false
|
|
219
|
+
end
|
|
159
220
|
end
|
|
160
221
|
end
|
|
161
222
|
end
|
data/lib/bookisbn/version.rb
CHANGED