relaton-iho 1.16.0 → 1.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +19 -8
- data/lib/relaton_iho/config.rb +10 -0
- data/lib/relaton_iho/iho_bibliography.rb +9 -4
- data/lib/relaton_iho/util.rb +9 -0
- data/lib/relaton_iho/version.rb +1 -1
- data/lib/relaton_iho.rb +6 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d710da9b97b769ffffa9b42765e8b953b42d78f9a1528ae84e0426562812af
|
4
|
+
data.tar.gz: 2776acafcc19b1e959ecc5c5f183ce74b4fa033ae40a40bfbe83379eebcd2a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae3afa87bd593e6245bdaedaed955ea3e4e5ae49f898549ce244e9742591aad80bf33a3436f334a9e1aea4d6898456741d5fada7a3d31d927be428311988f10
|
7
|
+
data.tar.gz: d91cd33057f9ad518a029820609396067d7152d3e75c5a81d10326d32e1107052477274f262225c3335b5e9d5cc31bbbc964e412d1ffa156754d8168ad6a82c3
|
data/README.adoc
CHANGED
@@ -37,26 +37,37 @@ $ gem install relaton-iho
|
|
37
37
|
|
38
38
|
== Usage
|
39
39
|
|
40
|
-
===
|
40
|
+
=== Configuration
|
41
41
|
|
42
|
-
|
42
|
+
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 `RelatonIho.configure` block.
|
43
43
|
|
44
44
|
[source,ruby]
|
45
45
|
----
|
46
46
|
require 'relaton_iho'
|
47
47
|
=> true
|
48
48
|
|
49
|
+
RelatonIho.configure do |config|
|
50
|
+
config.logger.level = Logger::DEBUG
|
51
|
+
end
|
52
|
+
----
|
53
|
+
|
54
|
+
=== Search for a standard using keywords
|
55
|
+
|
56
|
+
Reference can be specified with or without an edition. References without an edition will return the latest edition of the standard. References with an edition will return the standard with the specified edition.
|
57
|
+
|
58
|
+
[source,ruby]
|
59
|
+
----
|
49
60
|
# Search for a standard using a reference without an edition
|
50
61
|
item = RelatonIho::IhoBibliography.search("IHO B-11")
|
51
|
-
[relaton-iho] (
|
52
|
-
[relaton-iho] (
|
62
|
+
[relaton-iho] (IHO B-11) Fetching from Relaton repository ...
|
63
|
+
[relaton-iho] (IHO B-11) Found: `B-11`
|
53
64
|
=> #<RelatonIho::IhoBibliographicItem:0x007fe74fc80800
|
54
65
|
...
|
55
66
|
|
56
67
|
# Search for a standard using a reference with an edition
|
57
68
|
item = RelatonIho::IhoBibliography.search("IHO B-11 1.0.0")
|
58
|
-
[relaton-iho] (
|
59
|
-
[relaton-iho] (
|
69
|
+
[relaton-iho] (IHO B-11 1.0.0) Fetchint from Rlaont repository ...
|
70
|
+
[relaton-iho] (IHO B-11 1.0.0) Found: `B-11`
|
60
71
|
=> #<RelatonIho::IhoBibliographicItem:0x00007fe79d0ed698
|
61
72
|
...
|
62
73
|
----
|
@@ -95,8 +106,8 @@ item.to_xml bibdata: true
|
|
95
106
|
[source,ruby]
|
96
107
|
----
|
97
108
|
RelatonIho::IhoBibliography.get "IHO B-11"
|
98
|
-
[relaton-iho] (
|
99
|
-
[relaton-iho] (
|
109
|
+
[relaton-iho] (IHO B-11) Fetching from Relaton repository ...
|
110
|
+
[relaton-iho] (IHO B-11) Found: `B-11`
|
100
111
|
=> #<RelatonIho::IhoBibliographicItem:0x007fe78dbb7c78
|
101
112
|
...
|
102
113
|
----
|
@@ -14,21 +14,26 @@ module RelatonIho
|
|
14
14
|
# @return [RelatonIho::IhoBibliographicItem, nil] the IHO standard or nil if not found
|
15
15
|
#
|
16
16
|
def search(text, _year = nil, _opts = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
17
|
-
warn "
|
17
|
+
Util.warn "(#{text}) Fetching from Relaton repository ..."
|
18
18
|
ref = text.sub(/^IHO\s/, "").sub(/^([[:alpha:]]+)(\d+)/, '\1-\2')
|
19
19
|
index = Relaton::Index.find_or_create :iho, url: "#{ENDPOINT}index.zip"
|
20
20
|
row = index.search(ref).max_by { |r| r[:id] }
|
21
|
-
|
21
|
+
unless row
|
22
|
+
Util.warn "(#{text}) Not found."
|
23
|
+
return
|
24
|
+
end
|
22
25
|
|
23
26
|
uri = URI("#{ENDPOINT}#{row[:file]}")
|
24
27
|
resp = Net::HTTP.get_response uri
|
25
|
-
|
28
|
+
unless resp.code == "200"
|
29
|
+
raise RelatonBib::RequestError, "Could not access #{uri}: HTTP #{resp.code}"
|
30
|
+
end
|
26
31
|
|
27
32
|
yaml = RelatonBib.parse_yaml resp.body, [Date]
|
28
33
|
hash = HashConverter.hash_to_bib yaml
|
29
34
|
hash[:fetched] = Date.today.to_s
|
30
35
|
item = IhoBibliographicItem.new(**hash)
|
31
|
-
warn "
|
36
|
+
Util.warn "(#{text}) Found: `#{item.docidentifier.first.id}`"
|
32
37
|
item
|
33
38
|
rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
34
39
|
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
data/lib/relaton_iho/version.rb
CHANGED
data/lib/relaton_iho.rb
CHANGED
@@ -3,6 +3,8 @@ require "yaml"
|
|
3
3
|
require "relaton_bib"
|
4
4
|
require "relaton/index"
|
5
5
|
require "relaton_iho/version"
|
6
|
+
require "relaton_iho/config"
|
7
|
+
require "relaton_iho/util"
|
6
8
|
require "relaton_iho/iho_bibliography"
|
7
9
|
require "relaton_iho/hash_converter"
|
8
10
|
require "relaton_iho/xml_parser"
|
@@ -17,9 +19,9 @@ module RelatonIho
|
|
17
19
|
# Returns hash of XML reammar
|
18
20
|
# @return [String]
|
19
21
|
def self.grammar_hash
|
20
|
-
gem_path = File.expand_path "..", __dir__
|
21
|
-
grammars_path = File.join gem_path, "grammars", "*"
|
22
|
-
grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
|
23
|
-
Digest::MD5.hexdigest grammars
|
22
|
+
# gem_path = File.expand_path "..", __dir__
|
23
|
+
# grammars_path = File.join gem_path, "grammars", "*"
|
24
|
+
# grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
|
25
|
+
Digest::MD5.hexdigest RelatonIho::VERSION + RelatonBib::VERSION # grammars
|
24
26
|
end
|
25
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-iho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.16.
|
4
|
+
version: 1.16.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: relaton-bib
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- grammars/relaton-iho.rng
|
63
63
|
- lib/relaton_iho.rb
|
64
64
|
- lib/relaton_iho/comment_periond.rb
|
65
|
+
- lib/relaton_iho/config.rb
|
65
66
|
- lib/relaton_iho/editorial_group.rb
|
66
67
|
- lib/relaton_iho/eg.yml
|
67
68
|
- lib/relaton_iho/hash_converter.rb
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/relaton_iho/iho_bibliography.rb
|
70
71
|
- lib/relaton_iho/iho_group.rb
|
71
72
|
- lib/relaton_iho/processor.rb
|
73
|
+
- lib/relaton_iho/util.rb
|
72
74
|
- lib/relaton_iho/version.rb
|
73
75
|
- lib/relaton_iho/xml_parser.rb
|
74
76
|
- relaton_iho.gemspec
|