isbn 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/isbn.rb +5 -2
  3. data/test/isbn_spec.rb +2 -1
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
@@ -4,8 +4,11 @@ module ISBN
4
4
  def ten(isbn)
5
5
  isbn = isbn.delete("-")
6
6
  raise No10DigitISBNAvailable if isbn =~ /^979/
7
- isbn = isbn[/(?:978|290)*(.+)\w/,1] # remove 978, 979 or 290 and check digit
8
- raise Invalid10DigitISBN unless isbn.size == 9 # after removals isbn should be 9 digits
7
+ case isbn.size
8
+ when 10 then isbn = isbn[0..8]
9
+ when 13 then isbn = isbn[/(?:^978|^290)*(.{9})\w/,1]
10
+ else raise Invalid10DigitISBN
11
+ end
9
12
  case ck = (11 - (isbn.split(//).zip((2..10).to_a.reverse).inject(0) {|s,n| s += n[0].to_i * n[1]} % 11))
10
13
  when 10 then isbn << "X"
11
14
  when 11 then isbn << "0"
@@ -10,7 +10,8 @@ describe ISBN do
10
10
  ["0887273939","9780887273933"], ["012781910X","9780127819105"], ["0736061819","9780736061810"],
11
11
  ["0763748951","9780763748951"], ["0470196181","9780470196182"], ["0736064036","9780736064033"],
12
12
  ["0743488040","9780743488044"], ["0470130733","9780470130735"], ["0816516502","9780816516506"],
13
- ["074324382X","9780743243827"], ["0887401392","9780887401398"], ["0582404800","9780582404809"]]
13
+ ["074324382X","9780743243827"], ["0887401392","9780887401398"], ["0582404800","9780582404809"],
14
+ ["2906571385","9782906571389"]]
14
15
 
15
16
  it "should respond with a ten digit isbn" do
16
17
  ISBNS.each do |isbn|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isbn
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Kersey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-30 00:00:00 -07:00
12
+ date: 2009-11-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15