library_stdnums 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/lib/library_stdnums.rb +21 -0
- data/spec/library_stdnums_spec.rb +8 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
= library_stdnums
|
2
2
|
|
3
|
-
|
3
|
+
Do common operations on ISBNs, ISSN, and LCCNs.
|
4
|
+
|
5
|
+
What's supported:
|
6
|
+
|
7
|
+
* *ISBN* Compute or validate checkdigit; convert to/from ISBN-10 and ISBN-13
|
8
|
+
* *ISSN* Compute or validate checkdigit
|
9
|
+
* *LCCN* Normalize
|
4
10
|
|
5
11
|
== Note on Patches/Pull Requests
|
6
12
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/library_stdnums.rb
CHANGED
@@ -82,6 +82,27 @@ module StdNum
|
|
82
82
|
prefix = isbn[3..11]
|
83
83
|
return prefix + self.checkdigit(prefix + '0')
|
84
84
|
end
|
85
|
+
|
86
|
+
# Return an array of the ISBN10 and ISBN13 for the passed in value. You'll
|
87
|
+
# only get one value back if it's a 13-digit
|
88
|
+
# ISBN that can't be converted to an ISBN10.
|
89
|
+
# @param [String] isbn The original ISBN, in 10-character or 13-digit format
|
90
|
+
# @return [Array] Either the (one or two) normalized ISBNs, or an empty array if
|
91
|
+
# it can't be recognized.
|
92
|
+
|
93
|
+
def self.allNormalizedValues isbn
|
94
|
+
isbn = StdNum.extractNumber isbn
|
95
|
+
case isbn.size
|
96
|
+
when 10
|
97
|
+
return [isbn, self.convert_to_13(isbn)]
|
98
|
+
when 13
|
99
|
+
return [isbn, self.convert_to_10(isbn)].compact
|
100
|
+
else
|
101
|
+
return []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
85
106
|
end
|
86
107
|
|
87
108
|
module ISSN
|
@@ -53,7 +53,7 @@ describe "ISBN" do
|
|
53
53
|
StdNum::ISBN.valid?('9780306406157').should.equal true
|
54
54
|
end
|
55
55
|
|
56
|
-
it "finds a bad number
|
56
|
+
it "finds a bad number invalid" do
|
57
57
|
StdNum::ISBN.valid?('9780306406154').should.equal false
|
58
58
|
end
|
59
59
|
|
@@ -73,6 +73,13 @@ describe "ISBN" do
|
|
73
73
|
StdNum::ISBN.convert_to_10('978-0-306-40615-7').should.equal '0306406152'
|
74
74
|
end
|
75
75
|
|
76
|
+
it "gets both normalized values" do
|
77
|
+
a = StdNum::ISBN.allNormalizedValues('978-0-306-40615-7')
|
78
|
+
a.sort.should.equal ['9780306406157', '0306406152' ].sort
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
76
83
|
end
|
77
84
|
|
78
85
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: library_stdnums
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Dueber
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|