library_stdnums 1.1.0 → 1.2.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.
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ bundler_args: --without documentation
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+ - jruby-18mode
10
+ - rbx-18mode
@@ -0,0 +1,11 @@
1
+ --protected
2
+ --no-private
3
+ --embed-mixin ClassMethods
4
+ --markup=markdown
5
+ --markup-provider kramdown
6
+ --charset utf-8
7
+ --readme README.md
8
+ -
9
+ README.md
10
+ ChangeLog.md
11
+ LICENSE.txt
@@ -0,0 +1,26 @@
1
+ * 1.2.0 (2012.07.24)
2
+ * Added a bunch of tests for LCCN normalization from perl module Business::LCCN
3
+ (http://search.cpan.org/~anirvan/Business-LCCN/)
4
+ * Fix ISBN.normalize to fail if an invalid 10-digit ISBN in passed in
5
+ * Added ablility to normalize/validate LCCN URIs (e.g., http://lccn.loc.gov/abc89001234)
6
+ * Test give 100% code coverage! Yea!
7
+ * 1.1.0 (2012.02.06)
8
+ * Changed the ISBN/ISSN regex to make sure string of digits/dashes is at least 6 chars long
9
+ * Cleaned up LCCN validation code
10
+ * 1.0.2
11
+ * Made docs clearer.
12
+ * 1.0.0
13
+ * Added normalization all around.
14
+ * Added valid? for LCCN.
15
+ * Cleaner code all around, and better docs.
16
+ * 0.3.0
17
+ * Wow. ISBN-13 checkdigit wasn't changing '10' to '0'. Blatant error; bad coding *and* testing.
18
+ * 0.2.2
19
+ * Added ISSN.valid?
20
+ * Fixed error in ISSN.checksum when checksum was zero (was returning integer instead of string '0')
21
+ * 0.2.1
22
+ * Oops. Forgot to check to make sure there are *any* digits in the ISBN. fixed.
23
+ * 0.2.0
24
+ * Added allNormalizedValues for ISBN
25
+ * 0.1.0
26
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'bundler', '~> 1.0'
7
+ gem 'rake', '~> 0.8'
8
+ gem 'minitest'
9
+ end
10
+
11
+ group :documentation do
12
+ gem 'kramdown'
13
+ gem 'yard', '~> 0.7'
14
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Bill Dueber
1
+ Copyright (c) 2012 Bill Dueber
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,91 +1,90 @@
1
1
  # library_stdnums -- simple functions to check and normalize ISSN/ISBN/LCCN
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/billdueber/library_stdnums.png)](http://travis-ci.org/billdueber/library_stdnums)
4
+
3
5
  These are a set of Module functions (not classes with methods!) that perform simple checksum verification and (when applicable) normalization on strings containing common library types (currently just ISBN, ISSN, and LCCN).
4
6
 
5
7
  The code allows for some minimal crap to be in the passed string (e.g., '1234-4568 online' will work fine). All returned ISBN/ISSN values are devoid any dashes; any trailing X for an ISBN/ISSN checkdigit will be uppercase.
6
8
 
7
- When you're getting back just the checkdigit, it will *always be returned as a one-digit string or an uppercase X* ('1'..'9' or 'X').
9
+ When you're getting back just the checkdigit, it will *always be returned as a one-digit string or an uppercase X* ('1'..'9' or 'X').
8
10
 
9
11
 
10
12
  ## ISBN
11
13
 
12
- ````ruby
14
+ We can deal with 10 or 13-digit ISBNs and convert between the two (when applicable).
15
+ "Normalization" means converting to 13-digit string and then validating.
16
+
17
+ ~~~~~
13
18
 
14
19
  isbn = StdNum::ISBN.normalize(goodISBN)
15
20
  # => a 13-digit ISBN with no dashes/spaces
16
-
21
+
17
22
  isbn = StdNum::ISBN.normalize(badISBN)
18
23
  # => nil (if it's not an ISBN or the checkdigit is bad)
19
-
24
+
20
25
  tenDigit = StdNum::ISBN.convert_to_10(isbn13)
21
26
  thirteenDigit = StdNum::ISBN.convert_to_13(isbn10)
22
-
27
+
23
28
  thirteenDigit,tenDigit = StdNum::ISBN.allNormalizedValues(issn)
24
- # => array of the ten and thirteen digit isbns if valid;
29
+ # => array of the ten and thirteen digit isbns if valid;
25
30
  # an empty array if not
26
-
27
- digit = StdNum::ISBN.checkdigit(isbn)
31
+
32
+ digit = StdNum::ISBN.checkdigit(rawisbn)
28
33
  # => '0'..'9' (for isbn13) or '0'..'9','X' (for isbn10)
29
-
30
- if StdNum::ISBN.valid?(isbn)
34
+
35
+ digit = StdNum::ISBN.checkdigit(StdNum::ISBN.normalize(rawisbn))
36
+ # => '0'..'9', the checkdigit of the 13-digit ISBN
37
+
38
+ if StdNum::ISBN.valid?(rawisbn)
31
39
  puts "#{isbn} has a valid checkdigit"
32
40
  end
33
-
34
- ````
41
+
42
+ ~~~~~
35
43
 
36
44
  # ISSN
37
45
 
38
- ````ruby
39
- issn = StdNum::ISSN.normalize(issn)
46
+ For an ISSN, normalization simply cleans up any extraneous characters,
47
+ uppercases the final 'X' if need be, validates, and returns.
48
+
49
+ ~~~~~
50
+
51
+ issn = StdNum::ISSN.normalize(rawissn)
40
52
  # => the cleaned-up issn if valid; nil if not
41
-
42
- digit = StdNum::ISSN.checkdigit(issn)
53
+
54
+ digit = StdNum::ISSN.checkdigit(rawissn)
43
55
  # => '0'..'9' or 'X'
44
56
 
45
- if StdNum::ISSN.valid?(issn)
57
+ if StdNum::ISSN.valid?(rawissn)
46
58
  puts "#{issn} has a valid checkdigit"
47
59
  end
48
- ````
49
-
60
+ ~~~~~
61
+
50
62
  # LCCN
51
63
 
52
- LCCNs are normalized according to the algorithm at http://www.loc.gov/marc/lccn-namespace.html#syntax
53
-
54
- ````ruby
55
-
56
- lccn = StdNum::LCCN.normalize(rawlccn)
57
- # => either the normalized lccn, or nil if it has bad syntax
58
-
59
- if StdNum::LCCN.valid?(rawlccn) {
60
- puts "#{rawlccn} is valid"
61
- }
62
-
63
- ````
64
-
65
- ## CHANGES
66
- * 1.1.0 (2012.02.06)
67
- * Changed the ISBN/ISSN regex to make sure string of digits/dashes is at least 6 chars long
68
- * Cleaned up LCCN validation code
69
- * 1.0.2
70
- * Made docs clearer.
71
- * 1.0.0
72
- * Added normalization all around.
73
- * Added valid? for LCCN.
74
- * Cleaner code all around, and better docs.
75
- * 0.3.0
76
- * Wow. ISBN-13 checkdigit wasn't changing '10' to '0'. Blatant error; bad coding *and* testing.
77
- * 0.2.2
78
- * Added ISSN.valid?
79
- * Fixed error in ISSN.checksum when checksum was zero (was returning integer instead of string '0')
80
- * 0.2.1
81
- * Oops. Forgot to check to make sure there are *any* digits in the ISBN. fixed.
82
- * 0.2.0
83
- * Added allNormalizedValues for ISBN
84
- * 0.1.0
85
- * Initial release
64
+ LCCNs are normalized according to the algorithm at
65
+ http://www.loc.gov/marc/lccn-namespace.html#syntax . Normalization involves
66
+ that full process; validation includes checks on the syntax only since
67
+ there's no checkdigit.
68
+
69
+ rawlccn may be a standalone LCCN as found in a record, or a URI of the form
70
+ 'http://lccn.loc.gov/89001234 .
71
+
72
+ ~~~~~
73
+
74
+
75
+ lccn = StdNum::LCCN.normalize(rawlccn)
76
+ # => either the normalized lccn, or nil if it has bad syntax
77
+
78
+ if StdNum::LCCN.valid?(rawlccn) {
79
+ puts "#{rawlccn} is valid"
80
+ }
81
+
82
+
83
+ ~~~~~
84
+
86
85
 
87
86
  ## Note on Patches/Pull Requests
88
-
87
+
89
88
  * Fork the project.
90
89
  * Make your feature addition or bug fix.
91
90
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -1,53 +1,37 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
2
- require 'rake'
3
4
 
4
5
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "library_stdnums"
8
- gem.summary = %Q{Normalize and compute checkdigits for ISBN, ISSN, and LCCN}
9
- gem.description = %Q{Normalization and checksum computation for ISBN (10 and 13), ISSN, and LCCN}
10
- gem.email = "bill@dueber.com"
11
- gem.homepage = "http://github.com/billdueber/library_stdnums"
12
- gem.authors = ["Bill Dueber"]
13
- gem.add_development_dependency "minitest", ">= 0" if RUBY_VERSION < "1.9"
14
- gem.add_development_dependency "yard", ">= 0"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
21
-
22
- require 'rake/testtask'
23
- Rake::TestTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.pattern = 'spec/**/*_spec.rb'
26
- spec.verbose = true
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit e.status_code
27
11
  end
28
12
 
29
13
  begin
30
- require 'rcov/rcovtask'
31
- Rcov::RcovTask.new do |spec|
32
- spec.libs << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.verbose = true
35
- end
36
- rescue LoadError
37
- task :rcov do
38
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
- end
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
40
19
  end
41
20
 
42
- task :spec => :check_dependencies
21
+ require 'rake'
43
22
 
44
- task :default => :spec
23
+ require "bundler/gem_tasks"
45
24
 
46
- begin
47
- require 'yard'
48
- YARD::Rake::YardocTask.new
49
- rescue LoadError
50
- task :yardoc do
51
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
52
- end
25
+ require 'yard'
26
+ YARD::Rake::YardocTask.new
27
+ task :doc => :yard
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new do |test|
31
+ test.libs << 'spec'
32
+ test.pattern = 'spec/**/*_spec.rb'
33
+ test.verbose = true
53
34
  end
35
+
36
+ task :default => :test
37
+ task :spec => :test
@@ -0,0 +1,11 @@
1
+ name: library_stdnums
2
+ summary: "Normalize and validate ISBN / ISSN/ LCCN"
3
+ description: "A simple set of module functions to normalize, validate, and convert common library standard numbers"
4
+ license: MIT
5
+ authors: Bill Dueber
6
+ email: bill@dueber.com
7
+ homepage: https://github.com/billdueber/library_stdnums
8
+
9
+ development_dependencies:
10
+ bundler: ~> 1.0
11
+ yard: ~> 0.7
@@ -9,7 +9,7 @@ module StdNum
9
9
  # Since the shortest possible string is 7 digits followed by a checksum digit
10
10
  # for an ISSN, we'll make sure they're at least that long. Still imperfect
11
11
  # (would fine "5------", for example) but should work in most cases.
12
- STDNUMPAT = /^.*?(\d[\d\-]{6,}+[xX]?)/
12
+ STDNUMPAT = /^.*?(\d[\d\-]{6,}[xX]?)/
13
13
 
14
14
  # Extract the most likely looking number from the string. This will be the first
15
15
  # string of digits-and-hyphens-and-maybe-a-trailing-X, with the hypens removed
@@ -18,13 +18,13 @@ module StdNum
18
18
  def extractNumber str
19
19
  match = STDNUMPAT.match str
20
20
  return nil unless match
21
- return match[1].gsub(/\-/, '').upcase
21
+ return (match[1].gsub(/\-/, '')).upcase
22
22
  end
23
23
 
24
24
  # Given any string, extract what looks like the most likely ISBN/ISSN
25
25
  # of the given size(s), or nil if nothing matches at the correct size.
26
26
  # @param [String] rawnum The raw string containing (hopefully) an ISSN/ISBN
27
- # @param [Integer, Array<Integer>, nil] An integer or array of integers of valid sizes
27
+ # @param [Integer, Array<Integer>, nil] valid_sizes An integer or array of integers of valid sizes
28
28
  # for this type (e.g., 10 or 13 for ISBN, 8 for ISSN)
29
29
  # @return [String,nil] the reduced and verified number, or nil if there's no match at the right size
30
30
  def reduce_to_basics rawnum, valid_sizes = nil
@@ -96,13 +96,14 @@ module StdNum
96
96
  end
97
97
 
98
98
 
99
- # For an ISBN normalizing it is the same as converting to ISBN 13
99
+ # For an ISBN, normalizing it is the same as converting to ISBN 13
100
100
  # and making sure it's valid
101
- # @param [String] isbn The ISBN to normalize
101
+ #
102
+ # @param [String] rawisbn The ISBN to normalize
102
103
  # @return [String, nil] the normalized (to 13 digit) ISBN, or nil on failure
103
104
  def self.normalize rawisbn
104
105
  isbn = convert_to_13 rawisbn
105
- if isbn and valid?(isbn, true)
106
+ if isbn
106
107
  return isbn
107
108
  else
108
109
  return nil
@@ -118,6 +119,7 @@ module StdNum
118
119
  def self.convert_to_13 isbn
119
120
  isbn = reduce_to_basics isbn, [10,13]
120
121
  return nil unless isbn
122
+ return nil unless valid?(isbn, true)
121
123
  return isbn if isbn.size == 13
122
124
  prefix = '978' + isbn[0..8]
123
125
  return prefix + self.checkdigit(prefix + '0', true)
@@ -191,7 +193,7 @@ module StdNum
191
193
  end
192
194
 
193
195
  # Check to see if the checkdigit is correct
194
- # @param [String] isbn The ISSN (we'll try to clean it up if possible)
196
+ # @param [String] issn The ISSN (we'll try to clean it up if possible)
195
197
  # @param [Boolean] preprocessed Set to true if the number has already been through reduce_to_basic
196
198
  # @return [Boolean] Whether or not the checkdigit is correct
197
199
 
@@ -204,8 +206,8 @@ module StdNum
204
206
 
205
207
 
206
208
  # Make sure it's valid, remove the dashes, uppercase the X, and return
207
- # @param [String] isbn The ISBN to normalize
208
- # @return [String, nil] the normalized (to 13 digit) ISBN, or nil on failure
209
+ # @param [String] rawissn The ISSN to normalize
210
+ # @return [String, nil] the normalized ISSN, or nil on failure
209
211
  def self.normalize rawissn
210
212
  issn = reduce_to_basics rawissn, 8
211
213
  if issn and valid?(issn, true)
@@ -229,12 +231,13 @@ module StdNum
229
231
 
230
232
  def self.reduce_to_basic str
231
233
  rv = str.gsub(/\s/, '') # ditch spaces
234
+ rv.gsub!('http://lccn.loc.gov/', '') # remove URI prefix
232
235
  rv.gsub!(/\/.*$/, '') # ditch everything after the first '/' (including the slash)
233
236
  return rv
234
237
  end
235
238
 
236
239
  # Normalize based on data at http://www.loc.gov/marc/lccn-namespace.html#syntax
237
- # @param [String] str The possible LCCN to normalize
240
+ # @param [String] rawlccn The possible LCCN to normalize
238
241
  # @return [String, nil] the normalized LCCN, or nil if it looks malformed
239
242
  def self.normalize rawlccn
240
243
  lccn = reduce_to_basic(rawlccn)
@@ -268,6 +271,7 @@ module StdNum
268
271
 
269
272
  def self.valid? lccn, preprocessed = false
270
273
  lccn = normalize(lccn) unless preprocessed
274
+ return false unless lccn
271
275
  clean = lccn.gsub(/\-/, '')
272
276
  suffix = clean[-8..-1] # "the rightmost eight characters are always digits"
273
277
  return false unless suffix and suffix =~ /^\d+$/
@@ -285,10 +289,11 @@ module StdNum
285
289
  else
286
290
  return false
287
291
  end
292
+
293
+ return false
288
294
  end
289
295
 
290
296
  end
291
297
 
292
298
  end
293
299
 
294
-
@@ -0,0 +1,4 @@
1
+ module LibraryStdnums
2
+ # library_stdnums version
3
+ VERSION = "1.2.0"
4
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'library_stdnums/version'
14
+ LibraryStdnums::VERSION
15
+ end
16
+
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
+
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
28
+
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
31
+ end
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
33
+
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || 'spec/{**/}*_spec.rb}']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
37
+
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
41
+
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
46
+
47
+ split = lambda { |string| string.split(/,\s*/) }
48
+
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
52
+ end
53
+ end
54
+
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
58
+ end
59
+ end
60
+ end
@@ -85,9 +85,19 @@ describe "ISBN" do
85
85
  StdNum::ISBN.convert_to_10('978-0-306-40615-7').must_equal '0306406152'
86
86
  end
87
87
 
88
+ it "normalizes" do
89
+ StdNum::ISBN.normalize('0-306-40615-2').must_equal '9780306406157'
90
+ StdNum::ISBN.normalize('0-306-40615-X').must_equal nil
91
+ StdNum::ISBN.normalize('ISBN: 978-0-306-40615-7').must_equal '9780306406157'
92
+ StdNum::ISBN.normalize('ISBN: 978-0-306-40615-3').must_equal nil
93
+ end
94
+
88
95
  it "gets both normalized values" do
89
96
  a = StdNum::ISBN.allNormalizedValues('978-0-306-40615-7')
90
97
  a.sort.must_equal ['9780306406157', '0306406152' ].sort
98
+
99
+ a = StdNum::ISBN.allNormalizedValues('0-306-40615-2')
100
+ a.sort.must_equal ['9780306406157', '0306406152' ].sort
91
101
  end
92
102
 
93
103
 
@@ -107,7 +117,7 @@ describe 'ISSN' do
107
117
  end
108
118
 
109
119
 
110
- describe 'LCCN' do
120
+ describe 'LCCN basics' do
111
121
 
112
122
  # Tests take from http://www.loc.gov/marc/lccn-namespace.html#syntax
113
123
  test = {
@@ -127,5 +137,441 @@ describe 'LCCN' do
127
137
  end
128
138
  end
129
139
 
140
+ it "validates correctly" do
141
+ StdNum::LCCN.valid?("n78-890351").must_equal true
142
+ StdNum::LCCN.valid?("n78-89035100444").must_equal false, "Too long"
143
+ StdNum::LCCN.valid?("n78").must_equal false, "Too short"
144
+ StdNum::LCCN.valid?("na078-890351").must_equal false, "naa78-890351 should start with three letters or digits"
145
+ StdNum::LCCN.valid?("n078-890351").must_equal false, "n078-890351 should start with two letters or two digits"
146
+ StdNum::LCCN.valid?("na078-890351").must_equal false, "na078-890351 should start with three letters or digits"
147
+ StdNum::LCCN.valid?("0an78-890351").must_equal false, "0an78-890351 should start with three letters or digits"
148
+ StdNum::LCCN.valid?("n78-89c0351").must_equal false, "n78-89c0351 has a letter after the dash"
149
+ end
150
+
130
151
 
131
152
  end
153
+
154
+
155
+ describe "LCCN tests from Business::LCCN perl module" do
156
+ tests = [
157
+ { :orig => 'n78-890351',
158
+ :canonical => 'n 78890351 ',
159
+ :normalized => 'n78890351',
160
+ :prefix => 'n',
161
+ :year_cataloged => 1978,
162
+ :serial => '890351',
163
+ },
164
+ { :orig => 'n 78890351 ',
165
+ :canonical => 'n 78890351 ',
166
+ :normalized => 'n78890351',
167
+ :prefix => 'n',
168
+ :year_cataloged => 1978,
169
+ :serial => '890351',
170
+ },
171
+ { :orig => ' 85000002 ',
172
+ :canonical => ' 85000002 ',
173
+ :normalized => '85000002',
174
+ :year_cataloged => 1985,
175
+ :serial => '000002',
176
+ },
177
+ { :orig => '85-2 ',
178
+ :canonical => ' 85000002 ',
179
+ :normalized => '85000002',
180
+ :year_cataloged => 1985,
181
+ :serial => '000002',
182
+ },
183
+ { :orig => '2001-000002',
184
+ :canonical => ' 2001000002',
185
+ :normalized => '2001000002',
186
+ :year_cataloged => 2001,
187
+ :serial => '000002',
188
+ },
189
+ { :orig => '75-425165//r75',
190
+ :canonical => ' 75425165 //r75',
191
+ :normalized => '75425165',
192
+ :prefix => '',
193
+ :year_cataloged => nil,
194
+ :serial => '425165',
195
+ :revision_year => 1975,
196
+ :revision_year_encoded => '75',
197
+ :revision_number => nil,
198
+ },
199
+ { :orig => ' 79139101 /AC/r932',
200
+ :canonical => ' 79139101 /AC/r932',
201
+ :normalized => '79139101',
202
+ :prefix => '',
203
+ :year_cataloged => nil,
204
+ :serial => '139101',
205
+ :suffix_encoded => '/AC',
206
+ :revision_year => 1993,
207
+ :revision_year_encoded => '93',
208
+ :revision_number => 2,
209
+ },
210
+ { :orig => '89-4',
211
+ :canonical => ' 89000004 ',
212
+ :normalized => '89000004',
213
+ :year_cataloged => 1989,
214
+ :serial => '000004',
215
+ },
216
+ { :orig => '89-45',
217
+ :canonical => ' 89000045 ',
218
+ :normalized => '89000045',
219
+ :year_cataloged => 1989,
220
+ :serial => '000045',
221
+ },
222
+ { :orig => '89-456',
223
+ :canonical => ' 89000456 ',
224
+ :normalized => '89000456',
225
+ :year_cataloged => 1989,
226
+ :serial => '000456',
227
+ },
228
+ { :orig => '89-1234',
229
+ :canonical => ' 89001234 ',
230
+ :normalized => '89001234',
231
+ :year_cataloged => 1989,
232
+ :serial => '001234',
233
+ },
234
+ { :orig => '89-001234',
235
+ :canonical => ' 89001234 ',
236
+ :normalized => '89001234',
237
+ :year_cataloged => 1989,
238
+ :serial => '001234',
239
+ },
240
+ { :orig => '89001234',
241
+ :canonical => ' 89001234 ',
242
+ :normalized => '89001234',
243
+ :year_cataloged => 1989,
244
+ :serial => '001234',
245
+ },
246
+ { :orig => '2002-1234',
247
+ :canonical => ' 2002001234',
248
+ :normalized => '2002001234',
249
+ :year_cataloged => 2002,
250
+ :serial => '001234',
251
+ },
252
+ { :orig => '2002-001234',
253
+ :canonical => ' 2002001234',
254
+ :normalized => '2002001234',
255
+ :year_cataloged => 2002,
256
+ :serial => '001234',
257
+ },
258
+ { :orig => '2002001234',
259
+ :canonical => ' 2002001234',
260
+ :normalized => '2002001234',
261
+ :year_cataloged => 2002,
262
+ :serial => '001234',
263
+ },
264
+ { :orig => ' 89001234 ',
265
+ :canonical => ' 89001234 ',
266
+ :normalized => '89001234',
267
+ :year_cataloged => 1989,
268
+ :serial => '001234',
269
+ },
270
+ { :orig => ' 2002001234',
271
+ :canonical => ' 2002001234',
272
+ :normalized => '2002001234',
273
+ :year_cataloged => 2002,
274
+ :serial => '001234',
275
+ },
276
+ { :orig => 'a89-1234',
277
+ :canonical => 'a 89001234 ',
278
+ :normalized => 'a89001234',
279
+ :prefix => 'a',
280
+ :year_cataloged => 1989,
281
+ :serial => '001234',
282
+ },
283
+ { :orig => 'a89-001234',
284
+ :canonical => 'a 89001234 ',
285
+ :normalized => 'a89001234',
286
+ :prefix => 'a',
287
+ :year_cataloged => 1989,
288
+ :serial => '001234',
289
+ },
290
+ { :orig => 'a89001234',
291
+ :canonical => 'a 89001234 ',
292
+ :normalized => 'a89001234',
293
+ :prefix => 'a',
294
+ :year_cataloged => 1989,
295
+ :serial => '001234',
296
+ },
297
+ { :orig => 'a2002-1234',
298
+ :canonical => 'a 2002001234',
299
+ :normalized => 'a2002001234',
300
+ :prefix => 'a',
301
+ :year_cataloged => 2002,
302
+ :serial => '001234',
303
+ },
304
+ { :orig => 'a2002-001234',
305
+ :canonical => 'a 2002001234',
306
+ :normalized => 'a2002001234',
307
+ :prefix => 'a',
308
+ :year_cataloged => 2002,
309
+ :serial => '001234',
310
+ },
311
+ { :orig => 'a2002001234',
312
+ :canonical => 'a 2002001234',
313
+ :normalized => 'a2002001234',
314
+ :prefix => 'a',
315
+ :year_cataloged => 2002,
316
+ :serial => '001234',
317
+ },
318
+ { :orig => 'a 89001234 ',
319
+ :canonical => 'a 89001234 ',
320
+ :normalized => 'a89001234',
321
+ :prefix => 'a',
322
+ :year_cataloged => 1989,
323
+ :serial => '001234',
324
+ },
325
+ { :orig => 'a 89-001234 ',
326
+ :canonical => 'a 89001234 ',
327
+ :normalized => 'a89001234',
328
+ :prefix => 'a',
329
+ :year_cataloged => 1989,
330
+ :serial => '001234',
331
+ },
332
+ { :orig => 'a 2002001234',
333
+ :canonical => 'a 2002001234',
334
+ :normalized => 'a2002001234',
335
+ :prefix => 'a',
336
+ :year_cataloged => 2002,
337
+ :serial => '001234',
338
+ },
339
+ { :orig => 'ab89-1234',
340
+ :canonical => 'ab 89001234 ',
341
+ :normalized => 'ab89001234',
342
+ :prefix => 'ab',
343
+ :year_cataloged => 1989,
344
+ :serial => '001234',
345
+ },
346
+ { :orig => 'ab89-001234',
347
+ :canonical => 'ab 89001234 ',
348
+ :normalized => 'ab89001234',
349
+ :prefix => 'ab',
350
+ :year_cataloged => 1989,
351
+ :serial => '001234',
352
+ },
353
+ { :orig => 'ab89001234',
354
+ :canonical => 'ab 89001234 ',
355
+ :normalized => 'ab89001234',
356
+ :prefix => 'ab',
357
+ :year_cataloged => 1989,
358
+ :serial => '001234',
359
+ },
360
+ { :orig => 'ab2002-1234',
361
+ :canonical => 'ab2002001234',
362
+ :normalized => 'ab2002001234',
363
+ :prefix => 'ab',
364
+ :year_cataloged => 2002,
365
+ :serial => '001234',
366
+ },
367
+ { :orig => 'ab2002-001234',
368
+ :canonical => 'ab2002001234',
369
+ :normalized => 'ab2002001234',
370
+ :prefix => 'ab',
371
+ :year_cataloged => 2002,
372
+ :serial => '001234',
373
+ },
374
+ { :orig => 'ab2002001234',
375
+ :canonical => 'ab2002001234',
376
+ :normalized => 'ab2002001234',
377
+ :prefix => 'ab',
378
+ :year_cataloged => 2002,
379
+ :serial => '001234',
380
+ },
381
+ { :orig => 'ab 89001234 ',
382
+ :canonical => 'ab 89001234 ',
383
+ :normalized => 'ab89001234',
384
+ :prefix => 'ab',
385
+ :year_cataloged => 1989,
386
+ :serial => '001234',
387
+ },
388
+ { :orig => 'ab 2002001234',
389
+ :canonical => 'ab2002001234',
390
+ :normalized => 'ab2002001234',
391
+ :prefix => 'ab',
392
+ :year_cataloged => 2002,
393
+ :serial => '001234',
394
+ },
395
+ { :orig => 'ab 89-1234',
396
+ :canonical => 'ab 89001234 ',
397
+ :normalized => 'ab89001234',
398
+ :prefix => 'ab',
399
+ :year_cataloged => 1989,
400
+ :serial => '001234',
401
+ },
402
+ { :orig => 'abc89-1234',
403
+ :canonical => 'abc89001234 ',
404
+ :normalized => 'abc89001234',
405
+ :prefix => 'abc',
406
+ :year_cataloged => 1989,
407
+ :serial => '001234',
408
+ },
409
+ { :orig => 'abc89-001234',
410
+ :canonical => 'abc89001234 ',
411
+ :normalized => 'abc89001234',
412
+ :prefix => 'abc',
413
+ :year_cataloged => 1989,
414
+ :serial => '001234',
415
+ },
416
+ { :orig => 'abc89001234',
417
+ :canonical => 'abc89001234 ',
418
+ :normalized => 'abc89001234',
419
+ :prefix => 'abc',
420
+ :year_cataloged => 1989,
421
+ :serial => '001234',
422
+ },
423
+ { :orig => 'abc89001234 ',
424
+ :canonical => 'abc89001234 ',
425
+ :normalized => 'abc89001234',
426
+ :prefix => 'abc',
427
+ :year_cataloged => 1989,
428
+ :serial => '001234',
429
+ },
430
+ { :orig => 'http://lccn.loc.gov/89001234',
431
+ :canonical => ' 89001234 ',
432
+ :normalized => '89001234',
433
+ :year_cataloged => 1989,
434
+ :serial => '001234',
435
+ },
436
+ { :orig => 'http://lccn.loc.gov/a89001234',
437
+ :canonical => 'a 89001234 ',
438
+ :normalized => 'a89001234',
439
+ :serial => '001234',
440
+ :prefix => 'a',
441
+ :year_cataloged => 1989,
442
+ :serial => '001234',
443
+ },
444
+ { :orig => 'http://lccn.loc.gov/ab89001234',
445
+ :canonical => 'ab 89001234 ',
446
+ :normalized => 'ab89001234',
447
+ :prefix => 'ab',
448
+ :year_cataloged => 1989,
449
+ :serial => '001234',
450
+ },
451
+ { :orig => 'http://lccn.loc.gov/abc89001234',
452
+ :canonical => 'abc89001234 ',
453
+ :normalized => 'abc89001234',
454
+ :prefix => 'abc',
455
+ :year_cataloged => 1989,
456
+ :serial => '001234',
457
+ },
458
+ { :orig => 'http://lccn.loc.gov/2002001234',
459
+ :canonical => ' 2002001234',
460
+ :normalized => '2002001234',
461
+ :year_cataloged => 2002,
462
+ :serial => '001234',
463
+ },
464
+ { :orig => 'http://lccn.loc.gov/a2002001234',
465
+ :canonical => 'a 2002001234',
466
+ :normalized => 'a2002001234',
467
+ :prefix => 'a',
468
+ :year_cataloged => 2002,
469
+ :serial => '001234',
470
+ },
471
+ { :orig => 'http://lccn.loc.gov/ab2002001234',
472
+ :canonical => 'ab2002001234',
473
+ :normalized => 'ab2002001234',
474
+ :prefix => 'ab',
475
+ :year_cataloged => 2002,
476
+ :serial => '001234',
477
+ },
478
+ { :orig => '00-21595',
479
+ :canonical => ' 00021595 ',
480
+ :normalized => '00021595',
481
+ :year_cataloged => 2000,
482
+ :serial => '021595',
483
+ },
484
+ { :orig => '2001001599',
485
+ :canonical => ' 2001001599',
486
+ :normalized => '2001001599',
487
+ :year_cataloged => 2001,
488
+ :serial => '001599',
489
+ },
490
+ { :orig => '99-18233',
491
+ :canonical => ' 99018233 ',
492
+ :normalized => '99018233',
493
+ :year_cataloged => 1999,
494
+ :serial => '018233',
495
+ },
496
+ { :orig => '98000595',
497
+ :canonical => ' 98000595 ',
498
+ :normalized => '98000595',
499
+ :year_cataloged => 1898,
500
+ :serial => '000595',
501
+ },
502
+ { :orig => '99005074',
503
+ :canonical => ' 99005074 ',
504
+ :normalized => '99005074',
505
+ :year_cataloged => 1899,
506
+ :serial => '005074',
507
+ },
508
+ { :orig => '00003373',
509
+ :canonical => ' 00003373 ',
510
+ :normalized => '00003373',
511
+ :year_cataloged => 1900,
512
+ :serial => '003373',
513
+ },
514
+ { :orig => '01001599',
515
+ :canonical => ' 01001599 ',
516
+ :normalized => '01001599',
517
+ :year_cataloged => 1901,
518
+ :serial => '001599',
519
+ },
520
+ { :orig => ' 95156543 ',
521
+ :canonical => ' 95156543 ',
522
+ :normalized => '95156543',
523
+ :year_cataloged => 1995,
524
+ :serial => '156543',
525
+ },
526
+ { :orig => ' 94014580 /AC/r95',
527
+ :canonical => ' 94014580 /AC/r95',
528
+ :normalized => '94014580',
529
+ :year_cataloged => 1994,
530
+ :serial => '014580',
531
+ :suffix_encoded => '/AC',
532
+ :revision_year_encoded => '95',
533
+ :revision_year => 1995,
534
+ },
535
+ { :orig => ' 79310919 //r86',
536
+ :canonical => ' 79310919 //r86',
537
+ :normalized => '79310919',
538
+ :year_cataloged => 1979,
539
+ :serial => '310919',
540
+ :revision_year_encoded => '86',
541
+ :revision_year => 1986,
542
+ },
543
+ { :orig => 'gm 71005810 ',
544
+ :canonical => 'gm 71005810 ',
545
+ :normalized => 'gm71005810',
546
+ :prefix => 'gm',
547
+ :year_cataloged => 1971,
548
+ :serial => '005810',
549
+ },
550
+ { :orig => 'sn2006058112 ',
551
+ :canonical => 'sn2006058112',
552
+ :normalized => 'sn2006058112',
553
+ :prefix => 'sn',
554
+ :year_cataloged => 2006,
555
+ :serial => '058112',
556
+ },
557
+ { :orig => 'gm 71-2450',
558
+ :canonical => 'gm 71002450 ',
559
+ :normalized => 'gm71002450',
560
+ :prefix => 'gm',
561
+ :year_cataloged => 1971,
562
+ :serial => '002450',
563
+ },
564
+ { :orig => '2001-1114',
565
+ :canonical => ' 2001001114',
566
+ :normalized => '2001001114',
567
+ :year_cataloged => 2001,
568
+ :serial => '001114',
569
+ },
570
+ ]
571
+ tests.each do |h|
572
+ it "normalizes #{h[:orig]}" do
573
+ StdNum::LCCN.normalize(h[:orig]).must_equal h[:normalized], "#{h[:orig]} doesn't normalize to #{h[:normalized]}"
574
+ end
575
+ end
576
+ end
577
+
@@ -1,9 +1,3 @@
1
- require 'rubygems'
2
- begin
3
- gem 'minitest'
4
- rescue LoadError
5
- end
6
-
7
1
  require 'minitest/spec'
8
2
  require 'minitest/autorun'
9
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: library_stdnums
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,38 +9,67 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-16 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: yard
16
- requirement: &2153722800 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
19
- - - ! '>='
35
+ - - ~>
20
36
  - !ruby/object:Gem::Version
21
- version: '0'
37
+ version: '0.7'
22
38
  type: :development
23
39
  prerelease: false
24
- version_requirements: *2153722800
25
- description: Normalization and checksum computation for ISBN (10 and 13), ISSN, and
26
- LCCN
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.7'
46
+ description: A simple set of module functions to normalize, validate, and convert
47
+ common library standard numbers
27
48
  email: bill@dueber.com
28
49
  executables: []
29
50
  extensions: []
30
51
  extra_rdoc_files:
31
- - LICENSE
32
- - README.markdown
52
+ - ChangeLog.md
53
+ - LICENSE.txt
54
+ - README.md
33
55
  files:
34
- - .document
35
- - LICENSE
36
- - README.markdown
56
+ - .gitignore
57
+ - .travis.yml
58
+ - .yardopts
59
+ - ChangeLog.md
60
+ - Gemfile
61
+ - LICENSE.txt
62
+ - README.md
37
63
  - Rakefile
38
- - VERSION
64
+ - gemspec.yml
39
65
  - lib/library_stdnums.rb
66
+ - lib/library_stdnums/version.rb
67
+ - library_stdnums.gemspec
40
68
  - spec/library_stdnums_spec.rb
41
69
  - spec/spec_helper.rb
42
- homepage: http://github.com/billdueber/library_stdnums
43
- licenses: []
70
+ homepage: https://github.com/billdueber/library_stdnums
71
+ licenses:
72
+ - MIT
44
73
  post_install_message:
45
74
  rdoc_options: []
46
75
  require_paths:
@@ -59,8 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
88
  version: '0'
60
89
  requirements: []
61
90
  rubyforge_project:
62
- rubygems_version: 1.8.15
91
+ rubygems_version: 1.8.24
63
92
  signing_key:
64
93
  specification_version: 3
65
- summary: Normalize and compute checkdigits for ISBN, ISSN, and LCCN
94
+ summary: Normalize and validate ISBN / ISSN/ LCCN
66
95
  test_files: []
96
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0