relaton-iso 1.5.0 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8238914d2b7ec4d2bc0825eb915f9cfa0f902530b825a7e26fbe6c3034cc3a77
4
- data.tar.gz: 0d3f40d3e1961da0ee55af73b316824cf5706c4e4bb0e5d44514307049f4b01f
3
+ metadata.gz: a0484edee8670c0f8b65c5f16dd01ea45e29a4ef5cdfe6dbf8372063004cee71
4
+ data.tar.gz: 571928a396258e54eda1d06de63fa115adf16ba5be19461286bddd89e443681a
5
5
  SHA512:
6
- metadata.gz: 1788fa153b924357d86d5430a147d32da9e4a036a58179cbbe2057e0cb8c13567e9d78a3668fc4114e7233fb3f1a208a3dbb26080e0b0b90e430727e1ccab1dc
7
- data.tar.gz: e4e5c01f048d6b51638429d4bad4200ae0a4b964e67a2ff14389365a6d3e398b541301d11f26dc3053362f4f6ba11b22d66b2aa7df9385aa054569cd4939f480
6
+ metadata.gz: d3ef966a35e5adacf0238be0a30be5d259954507e08ffd0782e0fe3b5ba088e9a3535d22eb0377a3a15aa4393a157b8784184ec0d239af2d1268a8c09265c678
7
+ data.tar.gz: 6bde0ed1d2b918db22c0bf012d982e763a0f0aa01bcc20728d13bd20f040c3d690e39b8ddb5dc188654575166b633dedce607497c413906cb0fe5d2e113e486a
@@ -26,6 +26,8 @@ jobs:
26
26
  - name: Update gems
27
27
  run: |
28
28
  sudo gem install bundler --force
29
+ ruby -v | grep 2.5 && bundle config set build.debase --with-cflags="-Wno-error=implicit-function-declaration"
30
+ ruby -v | grep 2.5 && bundle config set build.ruby-debug-ide --with-cflags="-Wno-error=implicit-function-declaration"
29
31
  bundle install --jobs 4 --retry 3
30
32
  - name: Run specs
31
33
  run: |
@@ -29,7 +29,7 @@ module RelatonIso
29
29
  opts[:ref] = ref.gsub(/\u2013/, "-")
30
30
 
31
31
  %r{
32
- ^(?<code1>[^\s]+\s[^/]+) # match code
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
@@ -44,10 +44,16 @@ module RelatonIso
44
44
  year = year2 || year1
45
45
  end
46
46
  end
47
- opts[:all_parts] ||= code !~ %r{^[^\s]+\s\d+-\d+} && opts[:all_parts].nil? && code2.nil?
48
- return RelatonIec::IecBibliography.get(code, year, opts) if %r[^ISO/IEC DIR] =~ code
47
+ %r{\s(?<num>\d+)(-(?<part>[\d-]+))?} =~ code
48
+ opts[:part] = part
49
+ opts[:num] = num
50
+ opts[:corr] = corr
51
+ opts[:all_parts] ||= !part && opts[:all_parts].nil? && code2.nil?
52
+ if %r[^ISO/IEC DIR].match? code
53
+ return RelatonIec::IecBibliography.get(code, year, opts)
54
+ end
49
55
 
50
- ret = isobib_get1(code, year, corr, opts)
56
+ ret = isobib_get1(code, year, opts)
51
57
  return nil if ret.nil?
52
58
 
53
59
  if year || opts[:keep_year] || opts[:all_parts]
@@ -65,15 +71,18 @@ module RelatonIso
65
71
  id = year ? "#{code}:#{year}" : code
66
72
  warn "[relaton-iso] WARNING: no match found online for #{id}. "\
67
73
  "The code must be exactly like it is on the standards website."
68
- warn "[relaton-iso] (There was no match for #{year}, though there were matches "\
69
- "found for #{missed_years.join(', ')}.)" unless missed_years.empty?
70
- if /\d-\d/ =~ code
71
- warn "[relaton-iso] The provided document part may not exist, or the document "\
72
- "may no longer be published in parts."
74
+ unless missed_years.empty?
75
+ warn "[relaton-iso] (There was no match for #{year}, though there "\
76
+ "were matches found for #{missed_years.join(', ')}.)"
77
+ end
78
+ if /\d-\d/.match? code
79
+ warn "[relaton-iso] The provided document part may not exist, "\
80
+ "or the document may no longer be published in parts."
73
81
  else
74
- warn "[relaton-iso] If you wanted to cite all document parts for the reference, "\
75
- "use \"#{code} (all parts)\".\nIf the document is not a standard, "\
76
- "use its document type abbreviation (TS, TR, PAS, Guide)."
82
+ warn "[relaton-iso] If you wanted to cite all document parts for "\
83
+ "the reference, use \"#{code} (all parts)\".\nIf the document is "\
84
+ "not a standard, use its document type abbreviation (TS, TR, PAS, "\
85
+ "Guide)."
77
86
  end
78
87
  nil
79
88
  end
@@ -83,66 +92,74 @@ module RelatonIso
83
92
  # Search for hits. If no found then trying missed stages and ISO/IEC.
84
93
  #
85
94
  # @param code [String] reference without correction
86
- # @param corr [String] correction
95
+ # @param opts [Hash]
87
96
  # @return [Array<RelatonIso::Hit>]
88
- def isobib_search_filter(code, corr, opts)
97
+ def isobib_search_filter(code, opts)
89
98
  warn "[relaton-iso] (\"#{opts[:ref]}\") fetching..."
90
99
  result = search(code)
91
- res = search_code result, code, corr, opts
100
+ res = search_code result, code, opts
92
101
  return res unless res.empty?
93
102
 
94
103
  # try stages
95
104
  if %r{^\w+/[^/]+\s\d+} =~ code # code like ISO/IEC 123, ISO/IEC/IEE 123
96
- res = try_stages(result, corr, opts) do |st|
105
+ res = try_stages(result, opts) do |st|
97
106
  code.sub(%r{^(?<pref>[^\s]+\s)}) { "#{$~[:pref]}#{st} " }
98
107
  end
99
108
  return res unless res.empty?
100
109
  elsif %r{^\w+\s\d+} =~ code # code like ISO 123
101
- res = try_stages(result, corr, opts) do |st|
110
+ res = try_stages(result, opts) do |st|
102
111
  code.sub(%r{^(?<pref>\w+)}) { "#{$~[:pref]}/#{st}" }
103
112
  end
104
113
  return res unless res.empty?
105
114
  end
106
115
 
107
- if %r{^ISO\s} =~ code # try ISO/IEC if ISO not found
116
+ if %r{^ISO\s}.match? code # try ISO/IEC if ISO not found
108
117
  warn "[relaton-iso] Attempting ISO/IEC retrieval"
109
118
  c = code.sub "ISO", "ISO/IEC"
110
- res = search_code result, c, corr, opts
119
+ res = search_code result, c, opts
111
120
  end
112
121
  res
113
122
  end
114
123
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
115
124
 
116
125
  # @param result [RelatonIso::HitCollection]
117
- # @param corr [String] correction
118
126
  # @param opts [Hash]
119
- def try_stages(result, corr, opts)
127
+ # @return [RelatonIso::HitCollection]
128
+ def try_stages(result, opts)
120
129
  res = nil
121
130
  %w[NP WD CD DIS FDIS PRF IS AWI TR].each do |st| # try stages
122
131
  c = yield st
123
- res = search_code result, c, corr, opts
132
+ res = search_code result, c, opts
124
133
  return res unless res.empty?
125
134
  end
126
135
  res
127
136
  end
128
137
 
129
- def search_code(result, code, corr, opts)
138
+ # @param result [RelatonIso::HitCollection]
139
+ # @param code [String]
140
+ # @param opts [Hash]
141
+ # @return [RelatonIso::HitCollection]
142
+ def search_code(result, code, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
143
+ ref_regex = %r{^#{code}(?!-)}
144
+ corr_regex = %r{^#{code}[\w-]*(:\d{4})?/#{opts[:corr]}}
145
+ no_corr_regex = %r{^#{code}[\w-]*(:\d{4})?/}
130
146
  result.select do |i|
131
- (opts[:all_parts] || i.hit["docRef"] =~ %r{^#{code}(?!-)}) && (
132
- corr && %r{^#{code}[\w-]*(:\d{4})?/#{corr}} =~ i.hit["docRef"] ||
133
- !corr && %r{^#{code}[\w-]*(:\d{4})?/} !~ i.hit["docRef"]
134
- ) # && %r{^#{code}} =~ i.hit["docRef"]
147
+ (opts[:all_parts] || i.hit["docRef"] =~ ref_regex) && (
148
+ opts[:corr] && corr_regex =~ i.hit["docRef"] ||
149
+ !opts[:corr] && no_corr_regex !~ i.hit["docRef"]
150
+ )
135
151
  end
136
152
  end
137
153
 
138
154
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
139
155
 
140
156
  # Sort through the results from RelatonIso, fetching them three at a time,
141
- # and return the first result that matches the code,
142
- # matches the year (if provided), and which # has a title (amendments do not).
157
+ # and return the first result that matches the code, matches the year
158
+ # (if provided), and which # has a title (amendments do not).
143
159
  # Only expects the first page of results to be populated.
144
160
  # Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
145
- # If no match, returns any years which caused mismatch, for error reporting
161
+ # If no match, returns any years which caused mismatch, for error
162
+ # reporting
146
163
  def isobib_results_filter(result, year, opts)
147
164
  missed_years = []
148
165
  hits = result.reduce!([]) do |hts, h|
@@ -155,7 +172,9 @@ module RelatonIso
155
172
  end
156
173
  return { years: missed_years } unless hits.any?
157
174
 
158
- return { ret: hits.first.fetch(opts[:lang]) } if !opts[:all_parts] || hits.size == 1
175
+ if !opts[:all_parts] || hits.size == 1
176
+ return { ret: hits.first.fetch(opts[:lang]) }
177
+ end
159
178
 
160
179
  { ret: hits.to_all_parts(opts[:lang]) }
161
180
  end
@@ -163,11 +182,10 @@ module RelatonIso
163
182
 
164
183
  # @param code [String]
165
184
  # @param year [String, NilClass]
166
- # @param corr [String, NilClass]
167
185
  # @param opts [Hash]
168
- def isobib_get1(code, year, corr, opts)
186
+ def isobib_get1(code, year, opts)
169
187
  # return iev(code) if /^IEC 60050-/.match code
170
- result = isobib_search_filter(code, corr, opts) || return
188
+ result = isobib_search_filter(code, opts) || return
171
189
  ret = isobib_results_filter(result, year, opts)
172
190
  if ret[:ret]
173
191
  warn "[relaton-iso] (\"#{opts[:ref]}\") found #{ret[:ret].docidentifier.first.id}"
@@ -162,7 +162,7 @@ module RelatonIso
162
162
  [Nokogiri::HTML(resp.body), url]
163
163
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
164
164
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
165
- Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
165
+ Net::ProtocolError, Errno::ETIMEDOUT
166
166
  raise RelatonBib::RequestError, "Could not access #{url}"
167
167
  end
168
168
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -224,9 +224,8 @@ module RelatonIso
224
224
  # @param status [String]
225
225
  # @return [Hash]
226
226
  def fetch_status(doc)
227
- stg, substg = doc.css(
228
- "li.dropdown.active span.stage-code > strong"
229
- ).text.split "."
227
+ stg, substg = doc.at("//ul[@class='dropdown-menu']/li[@class='active']/a/span[@class='stage-code']")
228
+ .text.split "."
230
229
  RelatonBib::DocumentStatus.new(stage: stg, substage: substg)
231
230
  end
232
231
 
@@ -260,20 +259,15 @@ module RelatonIso
260
259
  # @param doc [Nokogiri::HTML::Document]
261
260
  # @return [Array<Hash>]
262
261
  def fetch_relations(doc) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
263
- doc.css("ul.steps li").reduce([]) do |a, r| # rubocop:disable Metrics/BlockLength
264
- r_type = r.css("strong").text
262
+ doc.xpath("//ul[@class='steps']/li", "//div[@class='sub-step']").reduce([]) do |a, r|
263
+ r_type = r.at("h4", "h5").text
265
264
  date = []
266
265
  type = case r_type
267
266
  when "Previously", "Will be replaced by" then "obsoletes"
268
- when "Corrigenda/Amendments", "Revised by", "Now confirmed"
269
- on = doc.xpath(
270
- '//span[@class="stage-date"][contains(., "-")]'
271
- ).last
272
- if on
273
- date << { type: "circulated",
274
- on: on.text }
275
- "updates"
276
- end
267
+ when "Corrigenda / Amendments", "Revised by", "Now confirmed"
268
+ on = doc.xpath('//span[@class="stage-date"][contains(., "-")]').last
269
+ date << { type: "circulated", on: on.text } if on
270
+ "updates"
277
271
  else r_type
278
272
  end
279
273
  if ["Now", "Now under review"].include?(type) then a
@@ -394,7 +388,8 @@ module RelatonIso
394
388
  links << { type: "obp", content: obp[:href] } if obp
395
389
  rss = doc.at("//a[contains(@href, 'rss')]")
396
390
  links << { type: "rss", content: DOMAIN + rss[:href] } if rss
397
- pub = doc.at "//p[contains(., 'publicly available')]/a"
391
+ pub = doc.at "//p[contains(., 'publicly available')]/a",
392
+ "//p[contains(., 'can be downloaded from the')]/a"
398
393
  links << { type: "pub", content: pub[:href] } if pub
399
394
  links
400
395
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.5.0"
4
+ VERSION = "1.7.2"
5
5
  end
@@ -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", "~> 1.5.0"
41
- spec.add_dependency "relaton-iso-bib", "~> 1.5.0"
40
+ spec.add_dependency "relaton-iec", "~> 1.7.0"
41
+ spec.add_dependency "relaton-iso-bib", "~> 1.7.0"
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.5.0
4
+ version: 1.7.2
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-10-09 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.5.0
159
+ version: 1.7.0
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.5.0
166
+ version: 1.7.0
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.5.0
173
+ version: 1.7.0
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.5.0
180
+ version: 1.7.0
181
181
  description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
182
182
  model'
183
183
  email: