bookland 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -4
- data/README.md +15 -25
- data/Rakefile +0 -12
- data/bookland.gemspec +5 -6
- data/lib/bookland/isbn.rb +25 -32
- data/lib/bookland/version.rb +1 -1
- data/spec/bookland/isbn_spec.rb +1 -1
- metadata +35 -72
- data/.rspec +0 -1
- data/.rvmrc +0 -3
- data/History.md +0 -9
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
Copyright (c) 2008, Keiichirou SHIKANO <k16.shikano@gmail.com>
|
2
|
-
shamelessly hacked by folks at Paper Cavalier in the year of the
|
3
|
-
Lord 2010.
|
4
|
-
|
1
|
+
Copyright (c) 2008, Keiichirou SHIKANO <k16.shikano@gmail.com>
|
5
2
|
All rights reserved.
|
6
3
|
|
7
4
|
Redistribution and use in source and binary forms, with or without
|
data/README.md
CHANGED
@@ -1,38 +1,28 @@
|
|
1
|
-
Bookland
|
2
|
-
========
|
1
|
+
# Bookland
|
3
2
|
|
4
|
-
[Bookland]
|
5
|
-
Ruby.
|
3
|
+
[Bookland] [1] provides an ISBN class in Ruby.
|
6
4
|
|
7
|
-
|
8
|
-
-----
|
5
|
+
[![travis](https://secure.travis-ci.org/hakanensari/bookland.png)](http://travis-ci.org/hakanensari/bookland)
|
9
6
|
|
10
|
-
|
7
|
+
## Usage
|
11
8
|
|
12
|
-
|
13
|
-
isbn10.to_isbn13
|
14
|
-
=> "9780262011532"
|
15
|
-
|
16
|
-
isbn10.to_s(1, 3, 5)
|
17
|
-
=> "0-262-01153-0"
|
9
|
+
require "bookland"
|
18
10
|
|
19
|
-
|
11
|
+
isbn = ISBN.new("0262011530")
|
12
|
+
isbn.to_isbn13
|
13
|
+
=> "9780262011532"
|
14
|
+
isbn.valid?
|
20
15
|
=> true
|
21
16
|
|
22
|
-
|
23
|
-
bad_isbn = ISBN.new('0262011531')
|
24
|
-
bad_isbn.valid?
|
25
|
-
=> false
|
26
|
-
bad_isbn.to_isbn13
|
27
|
-
=> Bookland::ISBNError: Invalid ISBN
|
17
|
+
Bookland provides certain utility methods defined on the class level:
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
ISBN.to_13('0262011530')
|
19
|
+
ISBN.to_13("0262011530")
|
32
20
|
=> "9780262011532"
|
33
21
|
|
34
|
-
ISBN.to_10(
|
22
|
+
ISBN.to_10("9780262011532")
|
35
23
|
=> "0262011530"
|
36
24
|
|
37
|
-
ISBN.valid?(
|
25
|
+
ISBN.valid?("9780262011532")
|
38
26
|
=> true
|
27
|
+
|
28
|
+
[1]: http://en.wikipedia.org/wiki/Bookland
|
data/Rakefile
CHANGED
@@ -9,15 +9,3 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
task :default => :spec
|
12
|
-
|
13
|
-
require 'rocco/tasks'
|
14
|
-
Rocco::make 'docs/'
|
15
|
-
|
16
|
-
desc 'Build rocco docs'
|
17
|
-
task :docs => :rocco
|
18
|
-
directory 'docs/'
|
19
|
-
|
20
|
-
desc 'Build docs and open in browser for the reading'
|
21
|
-
task :read => :docs do
|
22
|
-
sh 'open docs/lib/bookland/isbn.html'
|
23
|
-
end
|
data/bookland.gemspec
CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'bookland'
|
7
7
|
s.version = Bookland::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ['
|
9
|
+
s.authors = ['Hakan Ensari']
|
10
10
|
s.email = 'code@papercavalier.com'
|
11
|
-
s.homepage = 'https://
|
12
|
-
s.summary = %q{An ISBN class
|
13
|
-
s.description = %q{Bookland
|
11
|
+
s.homepage = 'https://github.com/hakanensari/bookland'
|
12
|
+
s.summary = %q{An ISBN class}
|
13
|
+
s.description = %q{Bookland provides an ISBN class.}
|
14
14
|
|
15
15
|
s.rubyforge_project = 'bookland'
|
16
16
|
|
@@ -19,6 +19,5 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
|
22
|
-
s.add_development_dependency('rspec', '~> 2.
|
23
|
-
s.add_development_dependency('rocco', '~> 0.6.0')
|
22
|
+
s.add_development_dependency('rspec', '~> 2.6')
|
24
23
|
end
|
data/lib/bookland/isbn.rb
CHANGED
@@ -1,32 +1,17 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# [Bookland][bl] is a simple ISBN class in Ruby.
|
1
|
+
# [Bookland][bl] is an ISBN class in Ruby.
|
4
2
|
#
|
5
3
|
# [bl]: http://en.wikipedia.org/wiki/Bookland
|
6
4
|
module Bookland
|
7
|
-
|
8
|
-
#### Public Interface
|
9
|
-
#
|
10
|
-
# `ISBN.new` takes an optional string. The string should look like an ISBN
|
11
|
-
# and may contain extra characters that are traditionally used to format
|
12
|
-
# ISBNs.
|
13
|
-
#
|
14
|
-
# The following are valid instantiations:
|
15
|
-
#
|
16
|
-
# isbn13 = ISBN.new('9780826476951')
|
17
|
-
# isbn10 = ISBN.new('0-8264-7695-3')
|
18
|
-
#
|
19
|
-
# isbn10 == isbn13
|
20
|
-
# => true
|
21
5
|
class ISBN
|
22
6
|
class << self
|
23
|
-
|
24
|
-
#
|
7
|
+
# Converts specified string to a 10-digit ISBN and returns its
|
8
|
+
# string representation.
|
25
9
|
def to_10(isbn)
|
26
10
|
new(isbn).to_isbn10.to_s
|
27
11
|
end
|
28
12
|
|
29
|
-
#
|
13
|
+
# Converts specified string to a 13-digit ISBN and returns its
|
14
|
+
# string representation.
|
30
15
|
def to_13(isbn)
|
31
16
|
new(isbn).to_isbn13.to_s
|
32
17
|
end
|
@@ -37,11 +22,22 @@ module Bookland
|
|
37
22
|
end
|
38
23
|
end
|
39
24
|
|
40
|
-
|
25
|
+
# Instantiates a new ISBN object.
|
26
|
+
#
|
27
|
+
# Takes an optional string. The string should look like an ISBN and
|
28
|
+
# may contain extra characters that are traditionally used to
|
29
|
+
# format ISBNs.
|
30
|
+
#
|
31
|
+
# The following are valid instantiations for the same ISBN:
|
32
|
+
#
|
33
|
+
# isbn13 = ISBN.new('9780826476951')
|
34
|
+
# isbn10 = ISBN.new('0-8264-7695-3')
|
35
|
+
#
|
36
|
+
def initialize(seed = nil)
|
41
37
|
self.seed = seed
|
42
38
|
end
|
43
39
|
|
44
|
-
# Returns
|
40
|
+
# Returns +true+ if the ISBN is equal to another specified ISBN.
|
45
41
|
def ==(other)
|
46
42
|
to_isbn13.to_s == other.to_isbn13.to_s
|
47
43
|
end
|
@@ -53,12 +49,11 @@ module Bookland
|
|
53
49
|
|
54
50
|
# Sets the seed of the ISBN based on a specified string.
|
55
51
|
def seed=(seed)
|
56
|
-
@raw = seed.gsub(/[
|
52
|
+
@raw = seed.gsub(/[^\dx]/i, '').split('') rescue []
|
57
53
|
end
|
58
54
|
|
59
|
-
# Casts the ISBN to a
|
55
|
+
# Casts the ISBN to a 10-digit ISBN.
|
60
56
|
def to_isbn10
|
61
|
-
|
62
57
|
raise ISBNError unless valid?
|
63
58
|
|
64
59
|
if isbn13?
|
@@ -80,17 +75,17 @@ module Bookland
|
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
|
-
#
|
78
|
+
# Returns a string representation of the ISBN.
|
84
79
|
#
|
85
|
-
# Takes an optional list of integers, which it then uses to dashify
|
86
|
-
# ISBN like so:
|
80
|
+
# Takes an optional list of integers, which it then uses to dashify
|
81
|
+
# the ISBN like so:
|
87
82
|
#
|
88
83
|
# isbn = ISBN.new('0826476953')
|
89
84
|
# isbn.to_s(1,4,4,1)
|
90
85
|
# => "0-8264-7695-3"
|
91
86
|
#
|
92
87
|
def to_s(*blocks)
|
93
|
-
return
|
88
|
+
return nil unless valid?
|
94
89
|
|
95
90
|
raw = @raw.dup
|
96
91
|
if blocks.any?
|
@@ -100,7 +95,7 @@ module Bookland
|
|
100
95
|
end
|
101
96
|
end
|
102
97
|
|
103
|
-
# Returns
|
98
|
+
# Returns +true+ if the ISBN is valid.
|
104
99
|
def valid?
|
105
100
|
if isbn10?
|
106
101
|
@raw[9] == check_digit_10(@raw)
|
@@ -142,5 +137,3 @@ module Bookland
|
|
142
137
|
end
|
143
138
|
end
|
144
139
|
end
|
145
|
-
|
146
|
-
# C'est ça.
|
data/lib/bookland/version.rb
CHANGED
data/spec/bookland/isbn_spec.rb
CHANGED
@@ -153,7 +153,7 @@ module Bookland
|
|
153
153
|
ISBN.new('9780485113358').to_s(3, 10).should eql '978-0485113358'
|
154
154
|
end
|
155
155
|
|
156
|
-
it "casts to string and
|
156
|
+
it "casts to string and hyphenates a ten-digit ISBN" do
|
157
157
|
ISBN.new('048511335X').to_s(1, 3, 5, 1).should eql '0-485-11335-X'
|
158
158
|
end
|
159
159
|
|
metadata
CHANGED
@@ -1,69 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookland
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Hakan Ensari
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-08-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70172727862740 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 5
|
33
|
-
- 0
|
34
|
-
version: 2.5.0
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
35
22
|
type: :development
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rocco
|
39
23
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 7
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 6
|
49
|
-
- 0
|
50
|
-
version: 0.6.0
|
51
|
-
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
description: Bookland is an ISBN class in Ruby.
|
24
|
+
version_requirements: *70172727862740
|
25
|
+
description: Bookland provides an ISBN class.
|
54
26
|
email: code@papercavalier.com
|
55
27
|
executables: []
|
56
|
-
|
57
28
|
extensions: []
|
58
|
-
|
59
29
|
extra_rdoc_files: []
|
60
|
-
|
61
|
-
files:
|
30
|
+
files:
|
62
31
|
- .gitignore
|
63
|
-
- .
|
64
|
-
- .rvmrc
|
32
|
+
- .travis.yml
|
65
33
|
- Gemfile
|
66
|
-
- History.md
|
67
34
|
- LICENSE
|
68
35
|
- README.md
|
69
36
|
- Rakefile
|
@@ -75,41 +42,37 @@ files:
|
|
75
42
|
- spec/bookland_spec.rb
|
76
43
|
- spec/fixtures/isbn
|
77
44
|
- spec/spec_helper.rb
|
78
|
-
|
79
|
-
homepage: https://rubygems.org/gems/bookland
|
45
|
+
homepage: https://github.com/hakanensari/bookland
|
80
46
|
licenses: []
|
81
|
-
|
82
47
|
post_install_message:
|
83
48
|
rdoc_options: []
|
84
|
-
|
85
|
-
require_paths:
|
49
|
+
require_paths:
|
86
50
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
52
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
segments:
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
segments:
|
94
58
|
- 0
|
95
|
-
|
96
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
hash: -3532017646566011220
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
61
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
103
67
|
- 0
|
104
|
-
|
68
|
+
hash: -3532017646566011220
|
105
69
|
requirements: []
|
106
|
-
|
107
70
|
rubyforge_project: bookland
|
108
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.8.6
|
109
72
|
signing_key:
|
110
73
|
specification_version: 3
|
111
|
-
summary: An ISBN class
|
112
|
-
test_files:
|
74
|
+
summary: An ISBN class
|
75
|
+
test_files:
|
113
76
|
- spec/bookland/isbn_spec.rb
|
114
77
|
- spec/bookland_spec.rb
|
115
78
|
- spec/fixtures/isbn
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color --format=documentation
|
data/.rvmrc
DELETED
data/History.md
DELETED