isbn 2.0.8 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -9
- data/Rakefile +13 -14
- data/lib/isbn.rb +7 -4
- data/test/isbn_spec.rb +5 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -6,23 +6,22 @@ Version 2.0
|
|
6
6
|
|
7
7
|
This library provides methods to manipulate isbns. As of version 2.0 there has been a near complete rewrite of this library but this time there are tests. A few methods have been removed. Here is what remains:
|
8
8
|
|
9
|
-
* ISBN.ten will return a 10 digit isbn if you give it a 10 or 13 digit isbn
|
10
|
-
- it will raise a No10DigitISBNAvailable error if given an isbn starting with 979
|
9
|
+
* `ISBN.ten` will return a 10 digit isbn if you give it a 10 or 13 digit isbn
|
10
|
+
- it will raise a `No10DigitISBNAvailable` error if given an isbn starting with 979
|
11
11
|
because 979 isbns do NOT have a 10 digit counterpart.
|
12
|
+
* `ISBN.thirteen` will return a 13 digit isbn if you give it 10 or thirteen digit isbn
|
12
13
|
|
13
|
-
* ISBN.
|
14
|
-
|
15
|
-
* ISBN.as_new will convert an isbn into the used book version for that isbn
|
14
|
+
* `ISBN.as_new` will convert an isbn into the used book version for that isbn
|
16
15
|
- for isbns starting with 978 it returns an isbn starting with 290
|
17
16
|
- for isbns starting with 979 it returns an isbn starting with 291
|
18
17
|
|
19
|
-
* ISBN.as_used will convert an isbn into the new book version for that isbn
|
18
|
+
* `ISBN.as_used` will convert an isbn into the new book version for that isbn
|
20
19
|
- for isbns starting with 290 it returns an isbn starting with 978
|
21
20
|
- for isbns starting with 291 it returns an isbn starting with 979
|
22
21
|
|
23
|
-
* ISBN.valid
|
22
|
+
* `ISBN.valid?` will compare the check digit of the passed in isbn with that of one it computes
|
24
23
|
|
25
|
-
* ISBN.from_image accept a jpeg of an isbn and OCR it into an isbn.
|
24
|
+
* `ISBN.from_image` accept a jpeg of an isbn and OCR it into an isbn.
|
26
25
|
- it depends on the LibJpeg and Gocr libraries. I recommend [Homebrew](http://github.com/mxcl/homebrew).
|
27
26
|
|
28
|
-
* ISBN.from_string fetches isbn from string
|
27
|
+
* `ISBN.from_string` fetches isbn from string
|
data/Rakefile
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
$:.unshift("lib") unless $:.include?("lib")
|
2
2
|
require "isbn"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
desc "Build, Install and Cleanup gem"
|
5
|
+
task :install do
|
6
|
+
`gem build isbn.gemspec`
|
7
|
+
`gem install isbn-#{ISBN::VERSION}.gem`
|
8
|
+
`rm isbn-#{ISBN::VERSION}.gem`
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
7
12
|
|
8
13
|
require 'rake/testtask'
|
9
14
|
Rake::TestTask.new(:test) do |test|
|
10
15
|
test.libs << "test"
|
11
|
-
test.pattern =
|
16
|
+
test.pattern = FileList['test/**/*_test.rb', 'test/**/*_spec.rb']
|
17
|
+
test.verbose = true
|
12
18
|
end
|
13
19
|
|
14
20
|
desc "publish to rubygems.org"
|
15
|
-
task :publish
|
21
|
+
task :publish do
|
22
|
+
`gem build isbn.gemspec`
|
23
|
+
`gem install isbn-#{ISBN::VERSION}.gem`
|
16
24
|
`gem push isbn-#{ISBN::VERSION}.gem`
|
17
25
|
`rm isbn-#{ISBN::VERSION}.gem`
|
18
26
|
end
|
19
|
-
|
20
|
-
task :default => :test
|
21
|
-
|
22
|
-
require 'rake/testtask'
|
23
|
-
Rake::TestTask.new(:test) do |test|
|
24
|
-
test.libs << 'test'
|
25
|
-
test.pattern = FileList['test/**/*_test.rb', 'test/**/*_spec.rb']
|
26
|
-
test.verbose = true
|
27
|
-
end
|
data/lib/isbn.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ISBN
|
2
2
|
extend self
|
3
3
|
|
4
|
-
VERSION = "2.0.
|
4
|
+
VERSION = "2.0.9"
|
5
5
|
|
6
6
|
def ten(isbn)
|
7
7
|
raise InvalidISBNError unless isbn.is_a? String
|
@@ -69,7 +69,7 @@ module ISBN
|
|
69
69
|
isbn = isbn.delete("-")
|
70
70
|
case isbn.size
|
71
71
|
when 13 then isbn[-1] == thirteen(isbn)[-1]
|
72
|
-
when 10 then isbn[-1] == ten(isbn)[-1]
|
72
|
+
when 10 then isbn[-1].upcase == ten(isbn)[-1]
|
73
73
|
else false
|
74
74
|
end
|
75
75
|
end
|
@@ -85,9 +85,12 @@ module ISBN
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def from_string(source)
|
88
|
-
|
88
|
+
regex = /(?:ISBN[- ]*13|ISBN[- ]*10|)\s*((?:(?:97[89])?[ -]?(?:[0-9][ -]*){9})[ -]*(?:[0-9xX]))/
|
89
|
+
match = source.scan(regex).flatten
|
90
|
+
match.map! { |i| i.gsub(/[\s-]+/, "-") }
|
91
|
+
match = match.find {|i| ISBN.valid?(i) }
|
89
92
|
raise InvalidSourceString unless match
|
90
|
-
match
|
93
|
+
match
|
91
94
|
end
|
92
95
|
|
93
96
|
def with_dashes(isbn)
|
data/test/isbn_spec.rb
CHANGED
@@ -59,11 +59,16 @@ describe ISBN do
|
|
59
59
|
ISBN.valid?("012781910X").must_equal true
|
60
60
|
ISBN.valid?("9887401392").must_equal false
|
61
61
|
ISBN.valid?("082047267").must_equal false
|
62
|
+
ISBN.valid?("3-540-49698-X").must_equal true
|
63
|
+
ISBN.valid?("3-540-49698-x").must_equal true
|
62
64
|
ISBN.valid?(nil).must_equal false
|
63
65
|
end
|
64
66
|
|
65
67
|
it "should get isbn from source string" do
|
66
68
|
ISBN.from_string("ISBN:978-83-7659-303-6\nmore of content").must_equal "978-83-7659-303-6"
|
69
|
+
ISBN.from_string("ISBN-13 978-3-540-49698-4 and more content").must_equal "978-3-540-49698-4"
|
70
|
+
ISBN.from_string("ISBN-10 3-921099-34-X and more content").must_equal "3-921099-34-X"
|
71
|
+
ISBN.from_string("ISBN-10 3-921099-34- x and more content").must_equal "3-921099-34-x"
|
67
72
|
end
|
68
73
|
|
69
74
|
it "should add dashes to isbn 13 without dashes" do
|
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.
|
4
|
+
version: 2.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: ! ' library to transform ISBN''s from new to used, between 10 and 13,
|
16
16
|
etc...
|