relaton-nist 0.7.0 → 0.9.1

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: c87f09763dbcc319401cbc3b2c86de4a1cdd60743f00db8526d2a28e52a71dfd
4
- data.tar.gz: 9d690b4c771ae2f7256c6dd0770022b7709e00f08ee4efa625cbb144d3ba80b6
3
+ metadata.gz: b76a47785318a2497fae5a3fdab022b16d6117ad91470a23c46e73773e1e59ea
4
+ data.tar.gz: b33350d778c2c378f208443e5d9a7b636d2f22ee1908a953b6200abed97a7fb5
5
5
  SHA512:
6
- metadata.gz: ad3251b6140a8b79de2a952eed6ba721011efe3d77dff8f195147e0a0819356a6dcd52b48868d883bbb8572d32ff27216ec29bc76f942e2da51c2f69f5a687e7
7
- data.tar.gz: a6f32c9121980c23c324e6a1c7daead5baf266401dcad3efab1dfe0f46e6d886b21c84fe9750df2ed1a14f3cfc2377183b497e95c84f739c8277e727514459f2
6
+ metadata.gz: 6ae73a5ae455ca08d1cefaf446a419c07fd1984f7f2e6105666aa87ed2dc01206c8c832d2b0a01cd273cbd5b6248b93b971ab8e68bfb36b2fe8a46a1e95bd09a
7
+ data.tar.gz: 20c7e25ea1fdaa2af341213dfe85ad81357bd40abd035a18468c0f168c5b149eb3e8e5a35d724bbc8838e184233774e6a66fdaaef6a5b1aaf8dc4c12dee63502
@@ -3,9 +3,6 @@
3
3
  module RelatonNist
4
4
  # Hit.
5
5
  class Hit < RelatonBib::Hit
6
- # @return [RelatonNist::HitCollection]
7
- attr_reader :hit_collection
8
-
9
6
  # Parse page.
10
7
  # @return [RelatonNist::NistBliographicItem]
11
8
  def fetch
@@ -13,30 +13,24 @@ module RelatonNist
13
13
  DATAFILEDIR = File.expand_path ".relaton/nist", Dir.home
14
14
  DATAFILE = File.expand_path "pubs-export.zip", DATAFILEDIR
15
15
 
16
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
17
-
18
16
  # @param ref_nbr [String]
19
17
  # @param year [String]
20
18
  # @param opts [Hash]
21
19
  # @option opts [String] :stage
22
20
  def initialize(ref_nbr, year = nil, opts = {})
23
- @text = ref_nbr
24
- @year = year
21
+ super ref_nbr, year
25
22
 
26
23
  /(?<docid>(SP|FIPS)\s[0-9-]+)/ =~ text
27
- hits = docid ? from_json(docid, **opts) : from_csrc(**opts)
24
+ @array = docid ? from_json(docid, **opts) : from_csrc(**opts)
28
25
 
29
- hits.sort! do |a, b|
26
+ @array.sort! do |a, b|
30
27
  if a.sort_value != b.sort_value
31
28
  b.sort_value - a.sort_value
32
29
  else
33
30
  (b.hit[:release_date] - a.hit[:release_date]).to_i
34
31
  end
35
32
  end
36
- concat hits
37
- @fetched = false
38
33
  end
39
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
40
34
 
41
35
  private
42
36
 
@@ -60,9 +60,12 @@ module RelatonNist
60
60
  def nistbib_get1(code, year, opts)
61
61
  result = nistbib_search_filter(code, year, opts) || (return nil)
62
62
  ret = nistbib_results_filter(result, year, opts)
63
- return ret[:ret] if ret[:ret]
64
-
65
- fetch_ref_err(code, year, ret[:years])
63
+ if ret[:ret]
64
+ warn "[relaton-nist] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
65
+ ret[:ret]
66
+ else
67
+ fetch_ref_err(code, year, ret[:years])
68
+ end
66
69
  end
67
70
 
68
71
  # Sort through the results from RelatonNist, fetching them three at a time,
@@ -108,32 +111,33 @@ module RelatonNist
108
111
  { years: missed_years }
109
112
  end
110
113
 
111
- def fetch_pages(s, n)
112
- workers = RelatonBib::WorkersPool.new n
114
+ def fetch_pages(hits, threads)
115
+ workers = RelatonBib::WorkersPool.new threads
113
116
  workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
114
- s.each_with_index { |hit, i| workers << { i: i, hit: hit } }
117
+ hits.each_with_index { |hit, i| workers << { i: i, hit: hit } }
115
118
  workers.end
116
- workers.result.sort { |x, y| x[:i] <=> y[:i] }.map { |x| x[:hit] }
119
+ workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
117
120
  end
118
121
 
119
122
  def nistbib_search_filter(code, year, opts)
120
- docid = code.match(%r{[0-9-]{3,}}).to_s
123
+ idregex = %r{[0-9-]{3,}}
124
+ docid = code.match(idregex).to_s
121
125
  serie = code.match(%r{(FISP|SP|NISTIR)(?=\s)})
122
- warn "fetching #{code}..."
126
+ warn "[relaton-nist] (\"#{code}\") fetching..."
123
127
  result = search(code, year, opts)
124
128
  result.select do |i|
125
- i.hit[:code]&.include?(docid) && (!serie || i.hit[:serie] == serie.to_s)
129
+ i.hit[:code]&.match(idregex).to_s == docid && (!serie || i.hit[:serie] == serie.to_s)
126
130
  end
127
131
  end
128
132
 
129
133
  def fetch_ref_err(code, year, missed_years)
130
134
  id = year ? "#{code}:#{year}" : code
131
- warn "WARNING: no match found online for #{id}. "\
135
+ warn "[relaton-nist] WARNING: no match found online for #{id}. "\
132
136
  "The code must be exactly like it is on the standards website."
133
- warn "(There was no match for #{year}, though there were matches "\
137
+ warn "[relaton-nist] (There was no match for #{year}, though there were matches "\
134
138
  "found for #{missed_years.join(', ')}.)" unless missed_years.empty?
135
139
  if /\d-\d/ =~ code
136
- warn "The provided document part may not exist, or the document "\
140
+ warn "[relaton-nist] The provided document part may not exist, or the document "\
137
141
  "may no longer be published in parts."
138
142
  end
139
143
  nil
@@ -235,7 +235,7 @@ module RelatonNist
235
235
  )
236
236
  end
237
237
  if contr["surname"]
238
- affiliation = RelatonBib::Affilation.new organization: org
238
+ affiliation = RelatonBib::Affiliation.new organization: org
239
239
  entity = RelatonBib::Person.new(
240
240
  name: full_name(contr, lang, script), affiliation: [affiliation],
241
241
  )
@@ -271,7 +271,7 @@ module RelatonNist
271
271
  url = nil
272
272
  end
273
273
  org = RelatonBib::Organization.new name: org_name, url: url, abbreviation: abbrev
274
- affiliation = RelatonBib::Affilation.new organization: org
274
+ affiliation = RelatonBib::Affiliation.new organization: org
275
275
  entity = RelatonBib::Person.new(
276
276
  name: fullname, affiliation: [affiliation],
277
277
  )
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.9.1".freeze
3
3
  end
@@ -3,8 +3,13 @@ module RelatonNist
3
3
  class << self
4
4
  def from_xml(xml)
5
5
  doc = Nokogiri::XML xml
6
+ doc.remove_namespaces!
6
7
  nistitem = doc.at("/bibitem|/bibdata")
7
- NistBibliographicItem.new(item_data(nistitem))
8
+ if nistitem
9
+ NistBibliographicItem.new(item_data(nistitem))
10
+ elsif
11
+ warn "[relaton-nist] can't find bibitem or bibdata element in the XML"
12
+ end
8
13
  end
9
14
 
10
15
  private
data/relaton_nist.gemspec CHANGED
@@ -23,18 +23,17 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
25
25
 
26
- spec.add_development_dependency "byebug"
27
26
  spec.add_development_dependency "debase"
28
27
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
29
28
  spec.add_development_dependency "pry-byebug"
30
29
  spec.add_development_dependency "rake", "~> 10.0"
31
30
  spec.add_development_dependency "rspec", "~> 3.0"
32
31
  spec.add_development_dependency "ruby-debug-ide"
32
+ spec.add_development_dependency "ruby-jing"
33
33
  spec.add_development_dependency "simplecov"
34
34
  spec.add_development_dependency "vcr"
35
35
  spec.add_development_dependency "webmock"
36
- spec.add_development_dependency "ruby-jing"
37
36
 
38
- spec.add_dependency "relaton-bib", "~> 0.7.0"
37
+ spec.add_dependency "relaton-bib", "~> 0.9.0"
39
38
  spec.add_dependency "rubyzip"
40
39
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.1
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-02-17 00:00:00.000000000 Z
11
+ date: 2020-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: byebug
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: debase
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +95,7 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: simplecov
98
+ name: ruby-jing
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
@@ -123,7 +109,7 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: vcr
112
+ name: simplecov
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - ">="
@@ -137,7 +123,7 @@ dependencies:
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
- name: webmock
126
+ name: vcr
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - ">="
@@ -151,7 +137,7 @@ dependencies:
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
- name: ruby-jing
140
+ name: webmock
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - ">="
@@ -170,14 +156,14 @@ dependencies:
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: 0.7.0
159
+ version: 0.9.0
174
160
  type: :runtime
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
164
  - - "~>"
179
165
  - !ruby/object:Gem::Version
180
- version: 0.7.0
166
+ version: 0.9.0
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: rubyzip
183
169
  requirement: !ruby/object:Gem::Requirement