relaton-iso 1.14.3 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/bundle +10 -15
- data/bin/byebug +3 -5
- data/bin/coderay +3 -5
- data/bin/htmldiff +3 -5
- data/bin/ldiff +3 -5
- data/bin/nokogiri +3 -5
- data/bin/pry +3 -5
- data/bin/racc +3 -5
- data/bin/rake +3 -5
- data/bin/rspec +3 -5
- data/bin/rubocop +3 -5
- data/bin/ruby-parse +3 -5
- data/bin/ruby-rewrite +3 -5
- data/bin/thor +3 -5
- data/lib/relaton_iso/hit_collection.rb +1 -1
- data/lib/relaton_iso/iso_bibliography.rb +3 -4
- data/lib/relaton_iso/scrapper.rb +54 -26
- data/lib/relaton_iso/version.rb +1 -1
- data/relaton_iso.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1966b5eb0acc358cee2af36c4ff33104e2174a85cdaa95a28293f6d949b57758
|
|
4
|
+
data.tar.gz: 722d7543449cb075e437147d5a13ac7bf24eac473451e67cb18445339c900ae4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e011446f93dddbc0c3395e70ac9789e2377fa0cb90061972b135c62854e8c3998d9f392d2dd40014c375e10fd5fe1ad6e20372554154342dedc6506938aedf9
|
|
7
|
+
data.tar.gz: '009732dfec3d23d8b1d40b4ff9ec46f46a3b21f0c6e07ef9f0963aaf2cb73fa52e8e0ed99048ebb96b03fa8a44b5c35280740e0ac801bb5c37b22118157d061c'
|
data/bin/bundle
CHANGED
|
@@ -41,7 +41,7 @@ m = Module.new do
|
|
|
41
41
|
gemfile = ENV["BUNDLE_GEMFILE"]
|
|
42
42
|
return gemfile if gemfile && !gemfile.empty?
|
|
43
43
|
|
|
44
|
-
File.expand_path("
|
|
44
|
+
File.expand_path("../Gemfile", __dir__)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def lockfile
|
|
@@ -60,24 +60,19 @@ m = Module.new do
|
|
|
60
60
|
Regexp.last_match(1)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
def bundler_version
|
|
64
|
-
@bundler_version ||=
|
|
65
|
-
env_var_version || cli_arg_version ||
|
|
66
|
-
lockfile_version
|
|
67
|
-
end
|
|
68
|
-
|
|
69
63
|
def bundler_requirement
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
@bundler_requirement ||=
|
|
65
|
+
env_var_version ||
|
|
66
|
+
cli_arg_version ||
|
|
67
|
+
bundler_requirement_for(lockfile_version)
|
|
68
|
+
end
|
|
75
69
|
|
|
76
|
-
|
|
70
|
+
def bundler_requirement_for(version)
|
|
71
|
+
return "#{Gem::Requirement.default}.a" unless version
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
bundler_gem_version = Gem::Version.new(version)
|
|
79
74
|
|
|
80
|
-
|
|
75
|
+
bundler_gem_version.approximate_recommendation
|
|
81
76
|
end
|
|
82
77
|
|
|
83
78
|
def load_bundler!
|
data/bin/byebug
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/coderay
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/htmldiff
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/ldiff
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/nokogiri
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/pry
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/racc
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/rake
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/rspec
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/rubocop
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/ruby-parse
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/ruby-rewrite
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
data/bin/thor
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
# this file is here to facilitate running it.
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
14
12
|
|
|
15
|
-
bundle_binstub = File.expand_path("
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
16
14
|
|
|
17
15
|
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
19
17
|
load(bundle_binstub)
|
|
20
18
|
else
|
|
21
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
@@ -18,7 +18,7 @@ module RelatonIso
|
|
|
18
18
|
# @return [RelatonIsoBib::IsoBibliographicItem, nil]
|
|
19
19
|
def to_all_parts(lang = nil) # rubocop:disable Metrics/CyclomaticComplexity
|
|
20
20
|
# parts = @array.reject { |h| h.hit["docPart"]&.empty? }
|
|
21
|
-
hit = @array.min_by { |h| h.pubid.part }
|
|
21
|
+
hit = @array.min_by { |h| h.pubid.part.to_i }
|
|
22
22
|
return @array.first&.fetch lang unless hit
|
|
23
23
|
|
|
24
24
|
bibitem = hit.fetch(lang)
|
|
@@ -59,8 +59,7 @@ module RelatonIso
|
|
|
59
59
|
# puts "xxxxx #{ret.docidentifier.first.id.inspect}"
|
|
60
60
|
response_docid = ret.docidentifier.first.id.sub(" (all parts)", "")
|
|
61
61
|
response_pubid = Pubid::Iso::Identifier.parse(response_docid)
|
|
62
|
-
|
|
63
|
-
puts "xxxxx query_pubid(#{query_pubid}) response_pubid(#{response_pubid})"
|
|
62
|
+
# puts "xxxxx query_pubid(#{query_pubid}) response_pubid(#{response_pubid})"
|
|
64
63
|
|
|
65
64
|
if query_pubid.to_s == response_pubid.to_s
|
|
66
65
|
warn "[relaton-iso] (\"#{query_pubid}\") Found exact match."
|
|
@@ -161,7 +160,7 @@ module RelatonIso
|
|
|
161
160
|
else
|
|
162
161
|
warn "[relaton-iso] (\"#{query_pubid}\") TIP: " \
|
|
163
162
|
"If you wish to cite all document parts for the reference, " \
|
|
164
|
-
"use (\"#{query_pubid.to_s(
|
|
163
|
+
"use (\"#{query_pubid.to_s(format: :ref_undated)} (all parts)\")."
|
|
165
164
|
end
|
|
166
165
|
|
|
167
166
|
unless %w(TS TR PAS Guide).include?(query_pubid.type)
|
|
@@ -219,7 +218,7 @@ module RelatonIso
|
|
|
219
218
|
query_pubid_without_year = query_pubid.dup
|
|
220
219
|
# remove year for query
|
|
221
220
|
query_pubid_without_year.year = nil
|
|
222
|
-
hit_collection = search(query_pubid_without_year.to_s
|
|
221
|
+
hit_collection = search(query_pubid_without_year.to_s)
|
|
223
222
|
|
|
224
223
|
# filter only matching hits
|
|
225
224
|
res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
|
data/lib/relaton_iso/scrapper.rb
CHANGED
|
@@ -57,11 +57,13 @@ module RelatonIso
|
|
|
57
57
|
# path = "/contents/data/standard#{hit_data['splitPath']}/"\
|
|
58
58
|
# "#{hit_data['csnumber']}.html"
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
path = hit.hit[:path].sub("/sites/isoorg", "")
|
|
61
|
+
doc, url = get_page "#{path}.html"
|
|
61
62
|
|
|
62
63
|
# Fetch edition.
|
|
63
64
|
edition = doc.at("//div[div[.='Edition']]/text()[last()]")
|
|
64
65
|
&.text&.match(/\d+$/)&.to_s
|
|
66
|
+
hit.pubid.base.edition ||= edition if hit.pubid.base
|
|
65
67
|
|
|
66
68
|
titles, abstract, langs = fetch_titles_abstract(doc, lang)
|
|
67
69
|
|
|
@@ -97,7 +99,7 @@ module RelatonIso
|
|
|
97
99
|
# @return [Array<RelatonBib::DocumentIdentifier>]
|
|
98
100
|
#
|
|
99
101
|
def fetch_relaton_docids(doc, pubid)
|
|
100
|
-
pubid.stage
|
|
102
|
+
pubid.stage ||= Pubid::Iso::Stage.new(harmonized_code: stage_code(doc))
|
|
101
103
|
[
|
|
102
104
|
RelatonIso::DocumentIdentifier.new(id: pubid, type: "ISO", primary: true),
|
|
103
105
|
RelatonIso::DocumentIdentifier.new(id: pubid, type: "URN"),
|
|
@@ -155,35 +157,57 @@ module RelatonIso
|
|
|
155
157
|
lgs
|
|
156
158
|
end
|
|
157
159
|
|
|
158
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
159
160
|
# Get page.
|
|
160
161
|
# @param path [String] page's path
|
|
161
162
|
# @return [Array<Nokogiri::HTML::Document, String>]
|
|
162
163
|
def get_page(path)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
case resp.code
|
|
167
|
-
when "301"
|
|
168
|
-
path = resp["location"]
|
|
169
|
-
url = DOMAIN + path
|
|
170
|
-
uri = URI url
|
|
171
|
-
resp = Net::HTTP.get_response(uri) # .encode("UTF-8")
|
|
172
|
-
when "404", "302"
|
|
173
|
-
raise RelatonBib::RequestError, "#{url} not found."
|
|
174
|
-
end
|
|
175
|
-
n = 0
|
|
176
|
-
while resp.body !~ /<strong/ && n < 10
|
|
177
|
-
resp = Net::HTTP.get_response(uri) # .encode("UTF-8")
|
|
178
|
-
n += 1
|
|
179
|
-
end
|
|
180
|
-
[Nokogiri::HTML(resp.body), url]
|
|
164
|
+
resp, uri = get_redirection path
|
|
165
|
+
doc = try_if_fail resp, uri
|
|
166
|
+
[doc, uri.to_s]
|
|
181
167
|
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
|
182
168
|
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
|
183
169
|
Net::ProtocolError, Errno::ETIMEDOUT
|
|
184
|
-
raise RelatonBib::RequestError, "Could not access #{
|
|
170
|
+
raise RelatonBib::RequestError, "Could not access #{uri}"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
#
|
|
174
|
+
# Get the page from the given path. If the page is redirected, get the
|
|
175
|
+
# page from the new path.
|
|
176
|
+
#
|
|
177
|
+
# @param [String] path path to the page
|
|
178
|
+
#
|
|
179
|
+
# @return [Array<Net::HTTPOK, URI>] HTTP response and URI
|
|
180
|
+
# @raise [RelatonBib::RequestError] if the page is not found
|
|
181
|
+
#
|
|
182
|
+
def get_redirection(path)
|
|
183
|
+
url = DOMAIN + path
|
|
184
|
+
uri = URI url
|
|
185
|
+
resp = Net::HTTP.get_response(uri)
|
|
186
|
+
raise RelatonBib::RequestError, "#{url} not found." if %w[404 302].include? resp.code
|
|
187
|
+
|
|
188
|
+
resp.code == "301" ? get_redirection(resp["location"]) : [resp, uri]
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# The iso.org site fails to respond sometimes. This method tries to get
|
|
193
|
+
# the response again.
|
|
194
|
+
#
|
|
195
|
+
# @param [Net::HTTPOK] resp HTTP response
|
|
196
|
+
# @param [URI::HTTPS] uri URI of the page
|
|
197
|
+
#
|
|
198
|
+
# @return [Nokogiri::HTML4::Document] document
|
|
199
|
+
# @raise [RelatonBib::RequestError] if the page could not be parsed
|
|
200
|
+
#
|
|
201
|
+
def try_if_fail(resp, uri)
|
|
202
|
+
10.times do
|
|
203
|
+
doc = Nokogiri::HTML(resp.body)
|
|
204
|
+
# stop trying if page has a document id
|
|
205
|
+
return doc if doc.at("//main/div/section/div/div/div/nav/h1")
|
|
206
|
+
|
|
207
|
+
resp = Net::HTTP.get_response(uri)
|
|
208
|
+
end
|
|
209
|
+
raise RelatonBib::RequestError, "Could not parse the page #{uri}"
|
|
185
210
|
end
|
|
186
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
187
211
|
|
|
188
212
|
#
|
|
189
213
|
# Generate docnumber.
|
|
@@ -206,7 +230,7 @@ module RelatonIso
|
|
|
206
230
|
def fetch_structuredidentifier(pubid) # rubocop:disable Metrics/MethodLength
|
|
207
231
|
RelatonIsoBib::StructuredIdentifier.new(
|
|
208
232
|
project_number: "#{pubid.publisher} #{pubid.number}",
|
|
209
|
-
part: pubid
|
|
233
|
+
part: pubid.part&.to_s, # &.sub(/^-/, ""),
|
|
210
234
|
type: pubid.publisher,
|
|
211
235
|
)
|
|
212
236
|
end
|
|
@@ -399,12 +423,16 @@ module RelatonIso
|
|
|
399
423
|
# Fetch copyright.
|
|
400
424
|
# @param doc [Nokogiri::HTML::Document]
|
|
401
425
|
# @return [Array<Hash>]
|
|
402
|
-
def fetch_copyright(doc)
|
|
426
|
+
def fetch_copyright(doc) # rubocop:disable Metrics/MethodLength
|
|
403
427
|
ref = item_ref doc
|
|
404
428
|
owner_name = ref.match(/.*?(?=\s)/).to_s
|
|
405
429
|
from = ref.match(/(?<=:)\d{4}/).to_s
|
|
406
430
|
if from.empty?
|
|
407
|
-
|
|
431
|
+
date = doc.at(
|
|
432
|
+
"//span[@itemprop='releaseDate']",
|
|
433
|
+
"//ul[@id='stages']/li[contains(@class,'active')]/ul/li[@class='active']/a/span[@class='stage-date']",
|
|
434
|
+
)
|
|
435
|
+
from = date.text.match(/\d{4}/).to_s
|
|
408
436
|
end
|
|
409
437
|
[{ owner: [{ name: owner_name }], from: from }]
|
|
410
438
|
end
|
data/lib/relaton_iso/version.rb
CHANGED
data/relaton_iso.gemspec
CHANGED
|
@@ -39,6 +39,6 @@ Gem::Specification.new do |spec|
|
|
|
39
39
|
spec.add_development_dependency "webmock"
|
|
40
40
|
|
|
41
41
|
spec.add_dependency "algolia"
|
|
42
|
-
spec.add_dependency "pubid-iso", "~> 0.
|
|
42
|
+
spec.add_dependency "pubid-iso", "~> 0.4.0"
|
|
43
43
|
spec.add_dependency "relaton-iso-bib", "~> 1.14.0"
|
|
44
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relaton-iso
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.15.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: 2023-02-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|
|
@@ -184,14 +184,14 @@ dependencies:
|
|
|
184
184
|
requirements:
|
|
185
185
|
- - "~>"
|
|
186
186
|
- !ruby/object:Gem::Version
|
|
187
|
-
version: 0.
|
|
187
|
+
version: 0.4.0
|
|
188
188
|
type: :runtime
|
|
189
189
|
prerelease: false
|
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
191
191
|
requirements:
|
|
192
192
|
- - "~>"
|
|
193
193
|
- !ruby/object:Gem::Version
|
|
194
|
-
version: 0.
|
|
194
|
+
version: 0.4.0
|
|
195
195
|
- !ruby/object:Gem::Dependency
|
|
196
196
|
name: relaton-iso-bib
|
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|