bookworm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,12 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "bookworm"
6
- s.version = "0.1.0"
6
+ s.version = "0.1.1"
7
7
  s.authors = ["Tyler Johnston"]
8
8
  s.email = ["tylerjohnst@gmail.com"]
9
9
  s.homepage = "http://github.com/tylerjohnst/bookworm"
10
- s.summary = %q{ISBN manipulation, conversion, and inspection for Ruby.}
11
- s.description = %q{Convert from 13 digit to 10 digit, from new to used, and back again. Detect used and new addendums in ISBN strings..}
10
+ s.summary = %q{ISBN/EAN manipulation, conversion, and inspection for Ruby.}
11
+ s.description = %q{Convert from 13 digit EAN to 10 digit ISBN, from new to used, and back again. Detect used and new addendum in ISBN strings.}
12
12
 
13
13
  s.rubyforge_project = "bookworm"
14
14
 
@@ -60,7 +60,8 @@ class Bookworm
60
60
  digit = identifier[index].to_i
61
61
  sum += index.even? ? digit : digit * 3
62
62
  end
63
- (10 - sum % 10).to_s
63
+ checksum = (10 - sum % 10)
64
+ checksum == 10 ? '0' : checksum.to_s
64
65
  end
65
66
 
66
67
  def ten_check_digit(identifier)
@@ -69,7 +70,12 @@ class Bookworm
69
70
  sum += (10 - index) * identifier[index].to_i
70
71
  end
71
72
  checksum = 11 - sum % 11
72
- checksum == 10 ? 'X' : checksum.to_s
73
+
74
+ case checksum
75
+ when 10 then "X"
76
+ when 11 then "0"
77
+ else checksum.to_s
78
+ end
73
79
  end
74
80
 
75
81
  def is_valid?
@@ -24,6 +24,7 @@ class BookwormTest < Test::Unit::TestCase
24
24
 
25
25
  def test_should_convert_from_ten_to_thirteen
26
26
  assert_equal '9780976805427', Bookworm.new("0976805421").as_new
27
+ assert_equal '', Bookworm.new("0073324922").as_new
27
28
  end
28
29
 
29
30
  def test_should_convert_to_new
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bookworm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tyler Johnston
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-15 00:00:00 Z
13
+ date: 2011-12-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: "0"
24
24
  type: :development
25
25
  version_requirements: *id001
26
- description: Convert from 13 digit to 10 digit, from new to used, and back again. Detect used and new addendums in ISBN strings..
26
+ description: Convert from 13 digit EAN to 10 digit ISBN, from new to used, and back again. Detect used and new addendum in ISBN strings.
27
27
  email:
28
28
  - tylerjohnst@gmail.com
29
29
  executables: []
@@ -67,6 +67,6 @@ rubyforge_project: bookworm
67
67
  rubygems_version: 1.8.11
68
68
  signing_key:
69
69
  specification_version: 3
70
- summary: ISBN manipulation, conversion, and inspection for Ruby.
70
+ summary: ISBN/EAN manipulation, conversion, and inspection for Ruby.
71
71
  test_files:
72
72
  - test/bookworm_test.rb