Skip to content

Commit

Permalink
fix issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Feb 29, 2024
1 parent 0b4e5f2 commit 60771a1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ end

=== Retrieving bibliographic items using OpenLibrary API

To retrieve bibliographic items, use `RelatonIsbn::OpenLibrary.get` method with ISBN-10 or ISBN-13 as an argument. Prefix `ISBN` and hyphens are optional. The method returns `RelatonBib::BibliographicItem` object.
To retrieve bibliographic items, use `RelatonIsbn::OpenLibrary.get` method with ISBN-10 or ISBN-13 as an argument. Allowed prefixes are `ISBN`, `isbn:`. Prefix and hyphens are optional. The method returns `RelatonBib::BibliographicItem` object.

[source,ruby]
----
# get document by ISBN-13
> bibitem = RelatonIsbn::OpenLibrary.get "ISBN 978-0-12-064481-0"
> ibitem = RelatonIsbn::OpenLibrary.get "ISBN 978-0-12-064481-0"
[relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ...
[relaton-isbn] (ISBN 9780120644810) Found: `9780120644810`
=> #<RelatonBib::BibliographicItem:0x0000000113889258
...
# get document by ISBN-10
> RelatonIsbn::OpenLibrary.get "0120644819"
[relaton-isbn] (ISBN 0120644819) Fetching from OpenLibrary ...
[relaton-isbn] (ISBN 0120644819) Found: `9780120644810`
> RelatonIsbn::OpenLibrary.get "isbn:0120644819"
[relaton-isbn] (isbn:0120644819) Fetching from OpenLibrary ...
[relaton-isbn] (isbn:0120644819) Found: `9780120644810`
=> #<RelatonBib::BibliographicItem:0x00000001098ac960
...
----
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_isbn/isbn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Isbn
# @param [String] isbn ISBN 13 number
#
def initialize(isbn)
@isbn = isbn&.delete("-")&.sub(/^ISBN\s/, "")
@isbn = isbn&.delete("-")&.sub(/^ISBN[\s:]/i, "")
end

def parse
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_isbn/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIsbn
VERSION = "1.18.0".freeze
VERSION = "1.18.1".freeze
end
10 changes: 10 additions & 0 deletions spec/relaton_isbn/isbn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
it "with nil" do
expect(described_class.new(nil).parse).to be_nil
end

context "with prefix" do
it "ISBN" do
expect(described_class.new("ISBN 0-12-064481-9").parse).to eq "9780120644810"
end

it "isbn:" do
expect(described_class.new("isbn:0-12-064481-9").parse).to eq "9780120644810"
end
end
end

context "check ISBN" do
Expand Down
8 changes: 3 additions & 5 deletions spec/vcr_cassettes/success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60771a1

Please sign in to comment.