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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 682a54fef2a04c1c69f46a4be1e5b6fb49fda2f7d2303609df8e114e13e5b51e
4
- data.tar.gz: 435a91ca68e5596ac4dedeb8c4c859b77f6c33990ebc9cdc9f11f991696fe987
3
+ metadata.gz: 8f7582fb853eb4d82e54ee93176c671ef5dd6ea97b8be445af7f1ebb2b573f3a
4
+ data.tar.gz: 2b4c905d15ee77a8d6b530c1adb0c4330f9f0c6e62bc6c8fff30973b95351345
5
5
  SHA512:
6
- metadata.gz: c9799a507fbc4916c48d262ab3c5b2baa810784b4b29668496d84557142bcb3c5bf851b946683cae9d283d48e0a543cd13bdb3d746258dc44dff704c6c9c95bf
7
- data.tar.gz: f710216c00a0ef4b988cbb427f29caee663ead64836ba0bd42065243fd60a8fefc4ef6b4b6d0aef84a2ca332e6f712cceec50f49553bf5fdd6dc1c86ca12a992
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 # get ISBN EAN UCC
33
- @isbn.group # get ISBN Group id
34
- @isbn.publisher #get ISBN publisher code
35
- @isbn.title #get ISBN publisher book title order
36
- @isbn.check_digit # get 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
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 10 - sum%10 == @isbn[12].to_i
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
- [@ean_ucc, @group, @publisher, @title, @check_digit].join(joiner)
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
- [@group, @publisher, @title, @check_digit].join(joiner)
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
@@ -1,3 +1,3 @@
1
1
  module Bookisbn
2
- VERSION = "0.1.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookisbn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huang Feilong