relaton-isbn 1.17.0 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +67 -7
- data/lib/relaton_isbn/isbn.rb +59 -0
- data/lib/relaton_isbn/open_library.rb +9 -6
- data/lib/relaton_isbn/version.rb +1 -1
- data/lib/relaton_isbn.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a40299890b8c876a1397a66412981b29dd420e55f469b0d1d751f3ecfe76ad0a
|
4
|
+
data.tar.gz: f6f18a46d654dc22fa0cdac813c023904b7a622b483f4ae9127c1e350a2f546b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc9da4bc8e27e6a3b5c9f664dba1db1e878e7b059af03eae7c19de912ada3a31f82364327e886fae55da77ce60441fc5b07bd4d83a23189b68371892857ea41
|
7
|
+
data.tar.gz: 557d400855efa4cb4ca264860ba525d1b0bbed5c2002788ad5d8bd41cbc70b4571431addf8c57f0e492d43969f4f7c606834afb77934b85258dce6440bb892ef
|
data/README.adoc
CHANGED
@@ -11,7 +11,7 @@ image:https://img.shields.io/github/commits-since/relaton/relaton-isbn/latest.sv
|
|
11
11
|
RelatonIsbn is a Ruby gem that implements the
|
12
12
|
https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
|
13
13
|
|
14
|
-
You can use it to retrieve metadata of Standards from https://
|
14
|
+
You can use it to retrieve metadata of Standards from https://openlibrary.org, and
|
15
15
|
access such metadata through the `BibliographicItem` object.
|
16
16
|
|
17
17
|
== Installation
|
@@ -53,20 +53,80 @@ RelatonIsbn.configure do |config|
|
|
53
53
|
end
|
54
54
|
----
|
55
55
|
|
56
|
-
=== Retrieving items
|
56
|
+
=== Retrieving bibliographic items using OpenLibrary API
|
57
57
|
|
58
|
-
|
59
|
-
flavor, such as a NIST or IEEE standard, the corresponding Relaton class object
|
60
|
-
will be returned via the call.
|
58
|
+
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.
|
61
59
|
|
62
60
|
[source,ruby]
|
63
61
|
----
|
64
|
-
# get document by ISBN
|
65
|
-
RelatonIsbn::OpenLibrary.get "ISBN
|
62
|
+
# get document by ISBN-13
|
63
|
+
> bibitem = RelatonIsbn::OpenLibrary.get "ISBN 978-0-12-064481-0"
|
66
64
|
[relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ...
|
67
65
|
[relaton-isbn] (ISBN 9780120644810) Found: `9780120644810`
|
68
66
|
=> #<RelatonBib::BibliographicItem:0x0000000113889258
|
69
67
|
...
|
68
|
+
|
69
|
+
# get document by ISBN-10
|
70
|
+
> RelatonIsbn::OpenLibrary.get "0120644819"
|
71
|
+
[relaton-isbn] (ISBN 0120644819) Fetching from OpenLibrary ...
|
72
|
+
[relaton-isbn] (ISBN 0120644819) Found: `9780120644810`
|
73
|
+
=> #<RelatonBib::BibliographicItem:0x00000001098ac960
|
74
|
+
...
|
75
|
+
----
|
76
|
+
|
77
|
+
=== Serializing bibliographic items
|
78
|
+
[source,ruby]
|
79
|
+
----
|
80
|
+
# serialize to XML
|
81
|
+
> puts bibitem.to_xml
|
82
|
+
<bibitem id="9780120644810" schema-version="v1.2.7">
|
83
|
+
<title type="main" format="text/plain">Graphics gems II</title>
|
84
|
+
<uri type="src">http://openlibrary.org/books/OL21119585M/Graphics_gems_II</uri>
|
85
|
+
<docidentifier type="ISBN" primary="true">9780120644810</docidentifier>
|
86
|
+
<date type="published">
|
87
|
+
<on>1991</on>
|
88
|
+
</date>
|
89
|
+
<contributor>
|
90
|
+
<role type="author"/>
|
91
|
+
<person>
|
92
|
+
<name>
|
93
|
+
<completename>James Arvo</completename>
|
94
|
+
</name>
|
95
|
+
</person>
|
96
|
+
</contributor>
|
97
|
+
<contributor>
|
98
|
+
<role type="publisher"/>
|
99
|
+
<organization>
|
100
|
+
<name>AP Professional</name>
|
101
|
+
</organization>
|
102
|
+
</contributor>
|
103
|
+
<place>
|
104
|
+
<city>Boston</city>
|
105
|
+
</place>
|
106
|
+
<place>
|
107
|
+
<city>London</city>
|
108
|
+
</place>
|
109
|
+
</bibitem>
|
110
|
+
|
111
|
+
# serialize to bibdata XML
|
112
|
+
> puts bibitem.to_xml bibdata: true
|
113
|
+
<bibdata schema-version="v1.2.7">
|
114
|
+
<title type="main" format="text/plain">Graphics gems II</title>
|
115
|
+
...
|
116
|
+
|
117
|
+
# serialize to hash
|
118
|
+
> bibitem.to_hash
|
119
|
+
=> {"schema-version"=>"v1.2.7",
|
120
|
+
"id"=>"9780120644810",
|
121
|
+
"title"=>[{"content"=>"Graphics gems II", "format"=>"text/plain", "type"=>"main"}],
|
122
|
+
"link"=>[{"content"=>"http://openlibrary.org/books/OL21119585M/Graphics_gems_II", "type"=>"src"}],
|
123
|
+
"docid"=>[{"id"=>"9780120644810", "type"=>"ISBN", "primary"=>true}],
|
124
|
+
"date"=>[{"type"=>"published", "value"=>"1991"}],
|
125
|
+
"contributor"=>
|
126
|
+
[{"person"=>{"name"=>{"completename"=>{"content"=>"James Arvo"}}, "url"=>"http://openlibrary.org/authors/OL2646519A/James_Arvo"}, "role"=>[{"type"=>"author"}]},
|
127
|
+
{"organization"=>{"name"=>[{"content"=>"AP Professional"}]}, "role"=>[{"type"=>"publisher"}]}],
|
128
|
+
"revdate"=>"1991",
|
129
|
+
"place"=>[{"city"=>"Boston"}, {"city"=>"London"}]}
|
70
130
|
----
|
71
131
|
|
72
132
|
== Development
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module RelatonIsbn
|
2
|
+
class Isbn
|
3
|
+
#
|
4
|
+
# Create ISBN object.
|
5
|
+
#
|
6
|
+
# @param [String] isbn ISBN 13 number
|
7
|
+
#
|
8
|
+
def initialize(isbn)
|
9
|
+
@isbn = isbn&.delete("-")&.sub(/^ISBN\s/, "")
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
convert_to13
|
14
|
+
end
|
15
|
+
|
16
|
+
def check?
|
17
|
+
case @isbn
|
18
|
+
when /^\d{9}[\dX]$/i then check10?
|
19
|
+
when /^\d{13}$/ then check13?
|
20
|
+
else false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def check10?
|
25
|
+
@isbn[9] == calc_check_digit10
|
26
|
+
end
|
27
|
+
|
28
|
+
def check13?
|
29
|
+
@isbn[12] == calc_check_digit13
|
30
|
+
end
|
31
|
+
|
32
|
+
def calc_check_digit10
|
33
|
+
sum = 0
|
34
|
+
@isbn[..-2].chars.each_with_index do |c, i|
|
35
|
+
sum += c.to_i * (10 - i)
|
36
|
+
end
|
37
|
+
chk = (11 - sum % 11) % 11
|
38
|
+
chk == 10 ? "X" : chk.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def calc_check_digit13
|
42
|
+
sum = 0
|
43
|
+
@isbn[..-2].chars.each_with_index do |c, i|
|
44
|
+
sum += c.to_i * (i.even? ? 1 : 3)
|
45
|
+
end
|
46
|
+
((10 - sum % 10) % 10).to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def convert_to13
|
50
|
+
return unless check?
|
51
|
+
|
52
|
+
return @isbn if @isbn.size == 13
|
53
|
+
|
54
|
+
@isbn = "978#{@isbn}"
|
55
|
+
@isbn[12] = calc_check_digit13
|
56
|
+
@isbn
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -7,10 +7,16 @@ module RelatonIsbn
|
|
7
7
|
|
8
8
|
ENDPOINT = "http://openlibrary.org/api/volumes/brief/isbn/".freeze
|
9
9
|
|
10
|
-
def get(ref, _date = nil, _opts = {})
|
10
|
+
def get(ref, _date = nil, _opts = {}) # rubocop:disable Metrics/MethodLength
|
11
11
|
Util.warn "(#{ref}) Fetching from OpenLibrary ..."
|
12
12
|
|
13
|
-
|
13
|
+
isbn = Isbn.new(ref).parse
|
14
|
+
unless isbn
|
15
|
+
Util.warn "(#{ref}) Incorrect ISBN."
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
resp = request_api isbn
|
14
20
|
unless resp
|
15
21
|
Util.warn "(#{ref}) Not found."
|
16
22
|
return
|
@@ -21,10 +27,7 @@ module RelatonIsbn
|
|
21
27
|
bib
|
22
28
|
end
|
23
29
|
|
24
|
-
def request_api(
|
25
|
-
/ISBN\s*(?<isbn>\w+)/ =~ ref
|
26
|
-
return unless isbn
|
27
|
-
|
30
|
+
def request_api(isbn)
|
28
31
|
uri = URI "#{ENDPOINT}#{isbn}.json"
|
29
32
|
response = Net::HTTP.get_response uri
|
30
33
|
return unless response.is_a? Net::HTTPSuccess
|
data/lib/relaton_isbn/version.rb
CHANGED
data/lib/relaton_isbn.rb
CHANGED
@@ -3,6 +3,7 @@ require "relaton_bib"
|
|
3
3
|
require_relative "relaton_isbn/version"
|
4
4
|
require_relative "relaton_isbn/config"
|
5
5
|
require_relative "relaton_isbn/util"
|
6
|
+
require_relative "relaton_isbn/isbn"
|
6
7
|
require_relative "relaton_isbn/parser"
|
7
8
|
require_relative "relaton_isbn/open_library"
|
8
9
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-isbn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: relaton-bib
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.18.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
|
-
version: 1.
|
26
|
+
version: 1.18.0
|
27
27
|
description: 'RelatonIsbn: retrieve publications by ISBN for bibliographic use using
|
28
28
|
the BibliographicItem model'
|
29
29
|
email:
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- lib/relaton_isbn.rb
|
41
41
|
- lib/relaton_isbn/config.rb
|
42
|
+
- lib/relaton_isbn/isbn.rb
|
42
43
|
- lib/relaton_isbn/open_library.rb
|
43
44
|
- lib/relaton_isbn/parser.rb
|
44
45
|
- lib/relaton_isbn/processor.rb
|