relaton-iso 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaton_iso/hit.rb +5 -4
- data/lib/relaton_iso/hit_collection.rb +5 -0
- data/lib/relaton_iso/iso_bibliography.rb +14 -16
- data/lib/relaton_iso/scrapper.rb +39 -13
- data/lib/relaton_iso/version.rb +1 -1
- data/relaton_iso.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abf60687d46a08d6b3f1ec1979849f8b13d33d174c7e65c992bf8f81db5a531c
|
4
|
+
data.tar.gz: 22f99b919161f9a36fe5f8292da573b050b0abd80218a4dcc6105d53b71cb46f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f357af63b1d9beeb1848a6f8a4a39d5f1a401a2d7947e59390144c9a9ab0bdc915a4ea342204f355cda395f739e963757d3e5b6e6a083cdb4230173f8b72c22
|
7
|
+
data.tar.gz: 3b7e1cb107ae0b41d50db54c595b88fbb6ddac865893ac2b08a2001fa3494e4ec0cb832352d7a24657b437c3b81985310735dce041434933f29693f2077568ef
|
data/lib/relaton_iso/hit.rb
CHANGED
@@ -10,11 +10,12 @@ module RelatonIso
|
|
10
10
|
@fetch ||= Scrapper.parse_page @hit, lang
|
11
11
|
end
|
12
12
|
|
13
|
+
# @return [Integer]
|
13
14
|
def sort_weight
|
14
|
-
case hit["publicationStatus"]
|
15
|
-
when "
|
16
|
-
when "
|
17
|
-
when "
|
15
|
+
case hit["publicationStatus"] && hit["publicationStatus"]["key"]
|
16
|
+
when "ENT_ACTIVE" then 0
|
17
|
+
when "ENT_PROGRESS" then 1
|
18
|
+
when "ENT_INACTIVE" then 2
|
18
19
|
else 3
|
19
20
|
end
|
20
21
|
end
|
@@ -5,6 +5,8 @@ require "relaton_iso/hit"
|
|
5
5
|
module RelatonIso
|
6
6
|
# Page of hit collection.
|
7
7
|
class HitCollection < RelatonBib::HitCollection
|
8
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
9
|
+
|
8
10
|
# @param text [String] reference to search
|
9
11
|
def initialize(text)
|
10
12
|
super
|
@@ -48,9 +50,12 @@ module RelatonIso
|
|
48
50
|
end
|
49
51
|
all_parts_item
|
50
52
|
end
|
53
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
51
54
|
|
52
55
|
private
|
53
56
|
|
57
|
+
# @param hit [Hash]
|
58
|
+
# @return [Date]
|
54
59
|
def parse_date(hit)
|
55
60
|
if hit["publicationDate"]
|
56
61
|
Date.strptime(hit["publicationDate"], "%Y-%m")
|
@@ -12,10 +12,10 @@ module RelatonIso
|
|
12
12
|
# @param text [String]
|
13
13
|
# @return [RelatonIso::HitCollection]
|
14
14
|
def search(text)
|
15
|
-
HitCollection.new text
|
16
|
-
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
17
|
-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
18
|
-
OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
|
15
|
+
HitCollection.new text.gsub(/\u2013/, "-")
|
16
|
+
rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
17
|
+
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
18
|
+
Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
|
19
19
|
raise RelatonBib::RequestError, "Could not access http://www.iso.org"
|
20
20
|
end
|
21
21
|
|
@@ -26,15 +26,15 @@ module RelatonIso
|
|
26
26
|
# return actual reference with year
|
27
27
|
# @return [String] Relaton XML serialisation of reference
|
28
28
|
def get(ref, year = nil, opts = {})
|
29
|
-
opts[:ref] = ref
|
29
|
+
opts[:ref] = ref.gsub(/\u2013/, "-")
|
30
30
|
|
31
31
|
%r{
|
32
32
|
^(?<code1>[^\s]+\s[^/]+) # match code
|
33
33
|
/?
|
34
34
|
(?<corr>(Amd|DAmd|(CD|WD|AWI|NP)\sAmd|Cor|CD\sCor|FDAmd|PRF\sAmd)\s\d+ # correction name
|
35
35
|
:?(\d{4})?(/Cor\s\d+:\d{4})?) # match correction year
|
36
|
-
}x =~ ref
|
37
|
-
code = code1 || ref
|
36
|
+
}x =~ opts[:ref]
|
37
|
+
code = code1 || opts[:ref]
|
38
38
|
|
39
39
|
if year.nil?
|
40
40
|
/^(?<code1>[^\s]+(\s\w+)?\s[\d-]+)(:(?<year1>\d{4}))?(?<code2>\s\w+)?/ =~ code
|
@@ -58,6 +58,8 @@ module RelatonIso
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
+
# rubocop:disable Metrics/MethodLength
|
62
|
+
|
61
63
|
def fetch_ref_err(code, year, missed_years)
|
62
64
|
id = year ? "#{code}:#{year}" : code
|
63
65
|
warn "[relaton-iso] WARNING: no match found online for #{id}. "\
|
@@ -75,13 +77,7 @@ module RelatonIso
|
|
75
77
|
nil
|
76
78
|
end
|
77
79
|
|
78
|
-
#
|
79
|
-
# workers = RelatonBib::WorkersPool.new n
|
80
|
-
# workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
|
81
|
-
# s.each_with_index { |hit, i| workers << { i: i, hit: hit } }
|
82
|
-
# workers.end
|
83
|
-
# workers.result.sort { |x, y| x[:i] <=> y[:i] }.map { |x| x[:hit] }
|
84
|
-
# end
|
80
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
85
81
|
|
86
82
|
# Search for hits. If no found then trying missed stages and ISO/IEC.
|
87
83
|
#
|
@@ -114,6 +110,7 @@ module RelatonIso
|
|
114
110
|
end
|
115
111
|
res
|
116
112
|
end
|
113
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
117
114
|
|
118
115
|
# @param result [RelatonIso::HitCollection]
|
119
116
|
# @param corr [String] correction
|
@@ -137,6 +134,8 @@ module RelatonIso
|
|
137
134
|
end
|
138
135
|
end
|
139
136
|
|
137
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
138
|
+
|
140
139
|
# Sort through the results from RelatonIso, fetching them three at a time,
|
141
140
|
# and return the first result that matches the code,
|
142
141
|
# matches the year (if provided), and which # has a title (amendments do not).
|
@@ -146,8 +145,6 @@ module RelatonIso
|
|
146
145
|
def isobib_results_filter(result, year, opts)
|
147
146
|
missed_years = []
|
148
147
|
hits = result.reduce!([]) do |hts, h|
|
149
|
-
# if !year && h.hit["publicationStatus"] == "Withdrawn"
|
150
|
-
# hts
|
151
148
|
if !year || %r{:(?<iyear>\d{4})} =~ h.hit["docRef"] && iyear == year
|
152
149
|
hts << h
|
153
150
|
else
|
@@ -161,6 +158,7 @@ module RelatonIso
|
|
161
158
|
|
162
159
|
{ ret: hits.to_all_parts(opts[:lang]) }
|
163
160
|
end
|
161
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
164
162
|
|
165
163
|
# @param code [String]
|
166
164
|
# @param year [String, NilClass]
|
data/lib/relaton_iso/scrapper.rb
CHANGED
@@ -25,6 +25,30 @@ module RelatonIso
|
|
25
25
|
"Guide" => "guide",
|
26
26
|
}.freeze
|
27
27
|
|
28
|
+
STGABBR = {
|
29
|
+
"00" => "NWIP",
|
30
|
+
"10" => "AWI",
|
31
|
+
"20" => "WD",
|
32
|
+
"30" => "CD",
|
33
|
+
"40" => "DIS",
|
34
|
+
"50" => "FDIS",
|
35
|
+
"60" => { "00" => "PRF", "60" => "FINAL" },
|
36
|
+
}.freeze
|
37
|
+
|
38
|
+
PUBLISHERS = {
|
39
|
+
"IEC" => { name: "International Electrotechnical Commission",
|
40
|
+
url: "www.iec.ch" },
|
41
|
+
"ISO" => { name: "International Organization for Standardization",
|
42
|
+
url: "www.iso.org" },
|
43
|
+
"IEEE" => { name: "Institute of Electrical and Electronics Engineers",
|
44
|
+
url: "www.ieee.org" },
|
45
|
+
"SAE" => { name: "SAE International", url: "www.sae.org" },
|
46
|
+
"CIE" => { name: " International Commission on Illumination",
|
47
|
+
url: "cie.co.at" },
|
48
|
+
"ASME" => { name: "American Society of Mechanical Engineers",
|
49
|
+
url: "www.asme.org" },
|
50
|
+
}.freeze
|
51
|
+
|
28
52
|
class << self
|
29
53
|
# Parse page.
|
30
54
|
# @param hit_data [Hash]
|
@@ -176,10 +200,17 @@ module RelatonIso
|
|
176
200
|
# @param status [String]
|
177
201
|
# @return [Hash]
|
178
202
|
def fetch_status(doc)
|
179
|
-
|
180
|
-
|
203
|
+
stg, substg = doc.css(
|
204
|
+
"li.dropdown.active span.stage-code > strong",
|
205
|
+
).text.split "."
|
206
|
+
RelatonBib::DocumentStatus.new(stage: stg, substage: substg)
|
181
207
|
end
|
182
208
|
|
209
|
+
# def stage(stg, substg)
|
210
|
+
# abbr = STGABBR[stg].is_a?(Hash) ? STGABBR[stg][substg] : STGABBR[stg]
|
211
|
+
# RelatonBib::DocumentStatus::Stage.new value: stg, abbreviation: abbr
|
212
|
+
# end
|
213
|
+
|
183
214
|
# Fetch workgroup.
|
184
215
|
# @param doc [Nokogiri::HTML::Document]
|
185
216
|
# @return [Hash]
|
@@ -303,17 +334,12 @@ module RelatonIso
|
|
303
334
|
end
|
304
335
|
|
305
336
|
def fetch_contributors(ref)
|
306
|
-
ref.sub(/\s.*/, "").split("/").
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
name = "International Organization for Standardization"
|
313
|
-
url = "www.iso.org"
|
314
|
-
end
|
315
|
-
{ entity: { name: name, url: url, abbreviation: abbrev },
|
316
|
-
role: [type: "publisher"] }
|
337
|
+
ref.sub(/\s.*/, "").split("/").reduce([]) do |mem, abbrev|
|
338
|
+
publisher = PUBLISHERS[abbrev]
|
339
|
+
next mem unless publisher
|
340
|
+
|
341
|
+
publisher[:abbreviation] = abbrev
|
342
|
+
mem << { entity: publisher, role: [type: "publisher"] }
|
317
343
|
end
|
318
344
|
end
|
319
345
|
# rubocop:enable Metrics/MethodLength
|
data/lib/relaton_iso/version.rb
CHANGED
data/relaton_iso.gemspec
CHANGED
@@ -37,6 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency "vcr"
|
38
38
|
spec.add_development_dependency "webmock"
|
39
39
|
|
40
|
-
spec.add_dependency "relaton-iec", "
|
41
|
-
spec.add_dependency "relaton-iso-bib", "
|
40
|
+
spec.add_dependency "relaton-iec", ">= 1.0.1"
|
41
|
+
spec.add_dependency "relaton-iso-bib", ">= 1.0.1"
|
42
42
|
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.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -154,30 +154,30 @@ dependencies:
|
|
154
154
|
name: relaton-iec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.0.
|
159
|
+
version: 1.0.1
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.0.
|
166
|
+
version: 1.0.1
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: relaton-iso-bib
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.0.
|
173
|
+
version: 1.0.1
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.0.
|
180
|
+
version: 1.0.1
|
181
181
|
description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
|
182
182
|
model'
|
183
183
|
email:
|