relaton-isbn 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67f72a126942d761c281807d95cfb1c4feefb68a00029f3d284cd19d77022288
4
+ data.tar.gz: fd31af74cfbaca0480129f4aa3f02e3cc4761022d2c3f2b8cb46c1278d46dd40
5
+ SHA512:
6
+ metadata.gz: 5d199ef47b949e0fdeec3b6fa2d43fe93e136faef853e6ab1cfa45e26378f2b4bdd2e308813f31eec60a60714ded305e85f9d67105b5224e03b92a4072f3feac
7
+ data.tar.gz: 68b8bb3a2a2ea06f687a984145dedde9a782bcb9979e4286ba17bbcad4bc9a039942efa4b20313d98fe765d0c2cd73cff2e4b2fe6baffa1113ec345986c933aa
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ # This project follows the Ribose OSS style guide.
2
+ # https://github.com/riboseinc/oss-guides
3
+ # All project-specific additions and overrides should be specified in this file.
4
+
5
+ require: rubocop-rails
6
+
7
+ inherit_from:
8
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
+ AllCops:
10
+ TargetRubyVersion: 2.7
11
+ Rails:
12
+ Enabled: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Andrei Kislichenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,90 @@
1
+ = Relaton-ISBN: retrieves bibliographic items using OpenLibrary API
2
+
3
+ image:https://img.shields.io/gem/v/relaton-isbn.svg["Gem Version", link="https://rubygems.org/gems/relaton-isbn"]
4
+ image:https://github.com/relaton/relaton-isbn/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-isbn/actions?workflow=macos"]
5
+ image:https://github.com/relaton/relaton-isbn/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/relaton/relaton-isbn/actions?workflow=windows"]
6
+ image:https://github.com/relaton/relaton-isbn/workflows/ubuntu/badge.svg["Build Status (Ubuntu)", link="https://github.com/relaton/relaton-isbn/actions?workflow=ubuntu"]
7
+ image:https://codeclimate.com/github/relaton/relaton-isbn/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-isbn"]
8
+ image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-isbn.svg["Pull Requests", link="https://github.com/relaton/relaton-isbn/pulls"]
9
+ image:https://img.shields.io/github/commits-since/relaton/relaton-isbn/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-isbn/releases"]
10
+
11
+ RelatonIsbn is a Ruby gem that implements the
12
+ https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
13
+
14
+ You can use it to retrieve metadata of Standards from https://crossref.org, and
15
+ access such metadata through the `BibliographicItem` object.
16
+
17
+ == Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ [source,ruby]
22
+ ----
23
+ gem 'relaton-isbn'
24
+ ----
25
+
26
+ And then execute:
27
+
28
+ [source,sh]
29
+ ----
30
+ $ bundle install
31
+ ----
32
+
33
+ Or install it yourself as:
34
+
35
+ [source,sh]
36
+ ----
37
+ $ gem install relaton-isbn
38
+ ----
39
+
40
+ == Usage
41
+
42
+ === Configuration
43
+
44
+ Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonIsbn.configure` block.
45
+
46
+ [source,ruby]
47
+ ----
48
+ require 'relaton_isbn'
49
+ => true
50
+
51
+ RelatonIsbn.configure do |config|
52
+ config.logger.level = Logger::DEBUG
53
+ end
54
+ ----
55
+
56
+ === Retrieving items of known type using OpenLibrary API
57
+
58
+ If the resulting bibliographic item returned from CrossRef is a known Relaton
59
+ flavor, such as a NIST or IEEE standard, the corresponding Relaton class object
60
+ will be returned via the call.
61
+
62
+ [source,ruby]
63
+ ----
64
+ # get document by ISBN
65
+ RelatonIsbn::OpenLibrary.get "ISBN 9780120644810"
66
+ [relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ...
67
+ [relaton-isbn] (ISBN 9780120644810) Found: `9780120644810`
68
+ => #<RelatonBib::BibliographicItem:0x0000000113889258
69
+ ...
70
+ ----
71
+
72
+ == Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
75
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
76
+ prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`. To
79
+ release a new version, update the version number in `version.rb`, and then run
80
+ `bundle exec rake release`, which will create a git tag for the version, push
81
+ git commits and the created tag, and push the `.gem` file to
82
+ https://rubygems.org[rubygems.org].
83
+
84
+ == Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/relaton/relaton-isbn.
87
+
88
+ == License
89
+
90
+ The gem is available as open source under the terms of the https://opensource.org/licenses/MIT[MIT License].
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec]
@@ -0,0 +1,10 @@
1
+ module RelatonIsbn
2
+ module Config
3
+ include RelatonBib::Config
4
+ end
5
+ extend Config
6
+
7
+ class Configuration < RelatonBib::Configuration
8
+ PROGNAME = "relaton-isbn".freeze
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ module RelatonIsbn
2
+ #
3
+ # Search ISBN in Openlibrary.
4
+ #
5
+ module OpenLibrary
6
+ extend self
7
+
8
+ ENDPOINT = "http://openlibrary.org/api/volumes/brief/isbn/".freeze
9
+
10
+ def get(ref, _date = nil, _opts = {})
11
+ Util.warn "(#{ref}) Fetching from OpenLibrary ..."
12
+
13
+ resp = request_api ref
14
+ unless resp
15
+ Util.warn "(#{ref}) Not found."
16
+ return
17
+ end
18
+
19
+ bib = Parser.parse resp
20
+ Util.warn "(#{ref}) Found: `#{bib.docidentifier.first.id}`"
21
+ bib
22
+ end
23
+
24
+ def request_api(ref)
25
+ /ISBN\s*(?<isbn>\w+)/ =~ ref
26
+ return unless isbn
27
+
28
+ uri = URI "#{ENDPOINT}#{isbn}.json"
29
+ response = Net::HTTP.get_response uri
30
+ return unless response.is_a? Net::HTTPSuccess
31
+
32
+ data = JSON.parse response.body
33
+ return unless data["records"]&.any?
34
+
35
+ data["records"].first.last
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,67 @@
1
+ module RelatonIsbn
2
+ #
3
+ # OpenLibrary document parser.
4
+ #
5
+ class Parser
6
+ ATTRS = %i[title docid link contributor date place].freeze
7
+
8
+ def initialize(doc)
9
+ @doc = doc
10
+ end
11
+
12
+ def self.parse(doc)
13
+ new(doc).parse
14
+ end
15
+
16
+ def parse
17
+ args = ATTRS.each_with_object({}) { |a, h| h[a] = send(a) }
18
+ RelatonBib::BibliographicItem.new(**args)
19
+ end
20
+
21
+ private
22
+
23
+ def title
24
+ t = [RelatonBib::TypedTitleString.new(content: @doc["data"]["title"], type: "main")]
25
+ if @doc["data"]["subtitle"]
26
+ t << RelatonBib::TypedTitleString.new(content: @doc["data"]["subtitle"], type: "subtitle")
27
+ end
28
+ t
29
+ end
30
+
31
+ def docid
32
+ isbn = @doc["details"]["bib_key"].split(":").last
33
+ [RelatonBib::DocumentIdentifier.new(id: isbn, type: "ISBN", primary: true)]
34
+ end
35
+
36
+ def link
37
+ [RelatonBib::TypedUri.new(content: @doc["recordURL"], type: "src")]
38
+ end
39
+
40
+ def contributor
41
+ create_authors + creaate_publishers
42
+ end
43
+
44
+ def create_authors
45
+ @doc["data"]["authors"].map do |a|
46
+ name = RelatonBib::FullName.new completename: RelatonBib::LocalizedString.new(a["name"])
47
+ entity = RelatonBib::Person.new name: name, url: a["url"]
48
+ RelatonBib::ContributionInfo.new entity: entity, role: [{ type: "author" }]
49
+ end
50
+ end
51
+
52
+ def creaate_publishers
53
+ @doc["data"]["publishers"].map do |p|
54
+ entity = RelatonBib::Organization.new name: RelatonBib::LocalizedString.new(p["name"])
55
+ RelatonBib::ContributionInfo.new entity: entity, role: [{ type: "publisher" }]
56
+ end
57
+ end
58
+
59
+ def date
60
+ @doc["publishDates"].map { RelatonBib::BibliographicDate.new type: "published", on: _1 }
61
+ end
62
+
63
+ def place
64
+ @doc["data"]["publish_places"]&.map { RelatonBib::Place.new city: _1["name"] }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,58 @@
1
+ require "relaton/processor"
2
+
3
+ module RelatonIsbn
4
+ class Processor < Relaton::Processor
5
+ attr_reader :idtype
6
+
7
+ def initialize # rubocop:disable Lint/MissingSuper
8
+ @short = :relaton_isbn
9
+ @prefix = "ISBN"
10
+ @defaultprefix = /^ISBN\s/
11
+ @idtype = "ISBN"
12
+ @datasets = %w[]
13
+ end
14
+
15
+ # @param code [String]
16
+ # @param date [String, nil] year
17
+ # @param opts [Hash]
18
+ # @return [RelatonBib::BibliographicItem]
19
+ def get(code, date, opts)
20
+ ::RelatonIsbn::OpenLibrary.get(code, date, opts)
21
+ end
22
+
23
+ #
24
+ # @param [String] source source name (bipm-data-outcomes, bipm-si-brochure,
25
+ # rawdata-bipm-metrologia)
26
+ # @param [Hash] opts
27
+ # @option opts [String] :output directory to output documents
28
+ # @option opts [String] :format
29
+ #
30
+ # def fetch_data(source, opts)
31
+ # DataFetcher.fetch(source, **opts)
32
+ # end
33
+
34
+ # @param xml [String]
35
+ # @return [RelatonBib::BibliographicItem]
36
+ def from_xml(xml)
37
+ ::RelatonBib::XMLParser.from_xml xml
38
+ end
39
+
40
+ # @param hash [Hash]
41
+ # @return [RelatonBib::BibliographicItem]
42
+ def hash_to_bib(hash)
43
+ ::RelatonBib::BibliographicItem.from_hash hash
44
+ end
45
+
46
+ # Returns hash of XML grammar
47
+ # @return [String]
48
+ def grammar_hash
49
+ @grammar_hash ||= ::RelatonIsbn.grammar_hash
50
+ end
51
+
52
+ #
53
+ # Remove index file
54
+ #
55
+ # def remove_index_file
56
+ # end
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ module RelatonIsbn
2
+ module Util
3
+ extend RelatonBib::Util
4
+
5
+ def self.logger
6
+ RelatonIsbn.configuration.logger
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module RelatonIsbn
2
+ VERSION = "1.17.0".freeze
3
+ end
@@ -0,0 +1,17 @@
1
+ require "net/http"
2
+ require "relaton_bib"
3
+ require_relative "relaton_isbn/version"
4
+ require_relative "relaton_isbn/config"
5
+ require_relative "relaton_isbn/util"
6
+ require_relative "relaton_isbn/parser"
7
+ require_relative "relaton_isbn/open_library"
8
+
9
+ module RelatonIsbn
10
+ module_function
11
+
12
+ # Returns hash of XML reammar
13
+ # @return [String]
14
+ def grammar_hash
15
+ Digest::MD5.hexdigest RelatonIsbn::VERSION + RelatonBib::VERSION # grammars
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module RelatonIsbn
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-isbn
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.17.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: relaton-bib
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.17.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.17.0
27
+ description: 'RelatonIsbn: retrieve publications by ISBN for bibliographic use using
28
+ the BibliographicItem model'
29
+ email:
30
+ - open.source@ribose.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - LICENSE.txt
38
+ - README.adoc
39
+ - Rakefile
40
+ - lib/relaton_isbn.rb
41
+ - lib/relaton_isbn/config.rb
42
+ - lib/relaton_isbn/open_library.rb
43
+ - lib/relaton_isbn/parser.rb
44
+ - lib/relaton_isbn/processor.rb
45
+ - lib/relaton_isbn/util.rb
46
+ - lib/relaton_isbn/version.rb
47
+ - sig/relaton_isbn.rbs
48
+ homepage: https://github.com/relaton/relaton-isbn
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/relaton/relaton-isbn
53
+ source_code_uri: https://github.com/relaton/relaton-isbn
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.7.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.3.26
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: 'RelatonIsbn: retrieve publications by ISBN for bibliographic use using the
73
+ BibliographicItem model'
74
+ test_files: []