lisbn 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzQ3YjU1OWQ1MTBlMzE0YTQzNWY3MDkxMjMzOGFmZTEyNWVkN2UzYQ==
5
- data.tar.gz: !binary |-
6
- NzVmYTg1NDJhZGY4ZjQ0YjdkOGZiMWI0N2E5NGYxODYxODE0ZTUzZA==
2
+ SHA1:
3
+ metadata.gz: 7feff3bafa16145d94e68ee9d1f0aaab6de9b1b7
4
+ data.tar.gz: 50ca1b290f5e675754c9d5259ec599f63611e802
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Y2VlYmVlZDAxODFkNTVjNTdkMTJiMTgyYjdjY2FlNjc3ODkxOGNlNjQ1Mzg3
10
- ZWU2NTc5Zjc4YTJjODBhMWExODgwYWMyN2U1MDBmYmViMWExMzRkYjAzMzJm
11
- N2IxMGNkYzEzMzEyNmZhMzFhYzRkMmQxNDljMDg2ZWYyYTAzMjk=
12
- data.tar.gz: !binary |-
13
- OTgyNWRiNWNhY2YzNjVkMmRlZDc4NzI5MDMzZTVlZjNlMWI4OTU4MGQxZjIz
14
- MmUzZmM3MTc4OTc3ZTAwMWFkMDEzOGY1ZDFiZWIxY2ZkMjEyNTBiMTFiMzA1
15
- NGM3N2M0ZmJlMWQ1MzA3N2FiMDM3OWFmYmExOGU5ZTEyNmUyOTM=
6
+ metadata.gz: 4d8f6db5914d2610753830fc5a4263c566dc55914344deefc89def2abd360ae325fb0e4f30ebc17bc0c4cdf40b46c4427ae27b81407408ac4a8817c7f0206ea8
7
+ data.tar.gz: 5113257edc5e682f6158d0ac9a37c9de2e1807fcebd2bae9caece588d907aef17a3cdbfd947a216a22a53d3d3094c6f6e63dd1fb6db11c685711f23441c12a7f
@@ -16,6 +16,16 @@ class Lisbn < String
16
16
  end
17
17
  end
18
18
 
19
+ def isbn_with_dash
20
+ if valid_isbn_13? && parts
21
+ parts.join("-")
22
+ elsif isbn.length > 3
23
+ isbn[0..-2] + "-" + isbn[-1]
24
+ else
25
+ isbn
26
+ end
27
+ end
28
+
19
29
  # Returns a valid ISBN in ISBN-10 format.
20
30
  # Returns nil if the ISBN is invalid or incapable of conversion to ISBN-10.
21
31
  def isbn10
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "lisbn"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.2.1"
15
+ gem.version = "0.2.2"
16
16
 
17
17
  gem.add_dependency "nori", "~> 2.0"
18
18
  gem.add_dependency "nokogiri"
@@ -55,6 +55,34 @@ describe "Lisbn" do
55
55
  end
56
56
  end
57
57
 
58
+ describe "#isbn_with_dash" do
59
+ subject { Lisbn.new(isbn) }
60
+
61
+ context "with a 13-digit ISBN" do
62
+ let(:isbn) { "9781402780592" }
63
+
64
+ it "returns the isbn with dashes between the parts" do
65
+ expect(subject.isbn_with_dash).to eq("978-1-4027-8059-2")
66
+ end
67
+ end
68
+
69
+ context "with a 10-digit ISBN" do
70
+ let(:isbn) { "1402780591" }
71
+
72
+ it "returns the isbn with a dash before the checkdigit" do
73
+ expect(subject.isbn_with_dash).to eq("140278059-1")
74
+ end
75
+ end
76
+
77
+ context "with a very short ISBN" do
78
+ let(:isbn) { "123" }
79
+
80
+ it "returns the isbn" do
81
+ expect(subject.isbn_with_dash).to eq(isbn)
82
+ end
83
+ end
84
+ end
85
+
58
86
  describe "#isbn10" do
59
87
  subject { Lisbn.new("9780000000002") }
60
88
 
@@ -0,0 +1,7 @@
1
+ require "multi_json"
2
+ require "nori"
3
+ require_relative "../lib/lisbn/ranges"
4
+
5
+ task :save_ranges_to_json do
6
+ Lisbn::Ranges.save_to_json!
7
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lisbn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Ragalie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nori
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Lisbn (pronounced "Lisbon") is a wrapper around String that adds methods
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .rspec
63
+ - ".gitignore"
64
+ - ".rspec"
65
65
  - Gemfile
66
66
  - LICENSE
67
67
  - README.md
@@ -76,6 +76,7 @@ files:
76
76
  - spec/cache_method_spec.rb
77
77
  - spec/lisbn_spec.rb
78
78
  - spec/spec_helper.rb
79
+ - tasks/save_ranges_to_json.rake
79
80
  homepage: https://github.com/ragalie/lisbn
80
81
  licenses: []
81
82
  metadata: {}
@@ -85,17 +86,17 @@ require_paths:
85
86
  - lib
86
87
  required_ruby_version: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - ! '>='
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
- - - ! '>='
94
+ - - ">="
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
98
  rubyforge_project:
98
- rubygems_version: 2.1.10
99
+ rubygems_version: 2.4.6
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: Provides methods for converting between ISBN-10 and ISBN-13, checking validity