uri-urn 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +5 -0
- data/README.markdown +1 -0
- data/lib/uri/urn/isbn.rb +19 -0
- data/test/uri/urn/test_isbn.rb +41 -0
- data/uri-urn.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceac9f15a424139fa6e8e2d6e3822c7dfe3c0b04
|
4
|
+
data.tar.gz: 1cfd4a1a3207aadd3aa1e9526c746c04e1605965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5dc4edaed6a38533cea3ccf91463e79ea0408a14938135dadc998e0a1ca6351458e05e87557e3dce7101807a524eeb52bb1dc238dcf18d0b94211df581ac99
|
7
|
+
data.tar.gz: 4c769a7b98f4c07f8b982dd84a075be6e8666a7291ff74caa0ae231c6ea52976cfd6a09954521b8a80ec87fb3fd245bbec237fe1af9fd70aaad76e20196ced4d
|
data/CHANGELOG.markdown
CHANGED
data/README.markdown
CHANGED
data/lib/uri/urn/isbn.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri/urn'
|
2
|
+
|
3
|
+
module URI
|
4
|
+
module URN
|
5
|
+
class ISBN < Generic
|
6
|
+
ISBN10_PATTERN = '(?:\d+-\d+-\d+-\d)|(?:\d{9}[\dXx])'.freeze
|
7
|
+
ISBN13_PATTERN = '(?:\d{3}-\d+-\d+-\d+-\d)|(?:\d{3}-\d{10})|(?:\d{13})'.freeze
|
8
|
+
NSS_PATTERN = "#{ISBN10_PATTERN}|#{ISBN13_PATTERN}".freeze
|
9
|
+
|
10
|
+
def normalize!
|
11
|
+
super
|
12
|
+
set_nss(self.nss.upcase.gsub('-', ''))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@@nids['ISBN'] = ISBN
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'uri/urn/isbn'
|
3
|
+
|
4
|
+
module URI::URN
|
5
|
+
|
6
|
+
class TestISBN < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@isbn_string = '978-1937785499'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_parse
|
12
|
+
uri = URI.parse("urn:isbn:#{@isbn_string}")
|
13
|
+
|
14
|
+
assert_instance_of ISBN, uri
|
15
|
+
assert_equal 'urn', uri.scheme
|
16
|
+
assert_equal 'isbn', uri.nid
|
17
|
+
assert_equal @isbn_string, uri.nss
|
18
|
+
assert_raise URI::InvalidComponentError do
|
19
|
+
URI.parse("urn:isbn:#{@isbn_string.chop}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_build
|
24
|
+
uri = URI::URN::ISBN.build([@isbn_string])
|
25
|
+
|
26
|
+
assert_instance_of ISBN, uri
|
27
|
+
assert_equal 'urn', uri.scheme
|
28
|
+
assert_equal 'isbn', uri.nid
|
29
|
+
assert_equal @isbn_string, uri.nss
|
30
|
+
assert_raise URI::InvalidComponentError do
|
31
|
+
URI::URN::ISBN.build([@isbn_string.chop])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_equal
|
36
|
+
assert URI.parse('urn:isbn:193435693X') == URI.parse('urn:isbn:193435693X')
|
37
|
+
assert URI.parse('urn:isbn:978-4274064616') == URI.parse('urn:isbn:9784274064616')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/uri-urn.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-urn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubygems-tasks
|
@@ -42,8 +42,10 @@ files:
|
|
42
42
|
- README.markdown
|
43
43
|
- Rakefile
|
44
44
|
- lib/uri/urn.rb
|
45
|
+
- lib/uri/urn/isbn.rb
|
45
46
|
- lib/uri/urn/uuid.rb
|
46
47
|
- test/uri/test_urn.rb
|
48
|
+
- test/uri/urn/test_isbn.rb
|
47
49
|
- test/uri/urn/test_uuid.rb
|
48
50
|
- uri-urn.gemspec
|
49
51
|
homepage: https://gitorious.org/uri-ext
|
@@ -73,3 +75,4 @@ summary: Adds URN Scheme support to URI lib.
|
|
73
75
|
test_files:
|
74
76
|
- test/uri/test_urn.rb
|
75
77
|
- test/uri/urn/test_uuid.rb
|
78
|
+
- test/uri/urn/test_isbn.rb
|