relaton-nist 0.5.0 → 0.8.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: af67a70401309cab1e7d7b4511db20533a82927fc71aa4c439ee895bce140d2a
4
- data.tar.gz: aa32fd8f52b1b3513153fdf6ee2d0898d16dfe4e86b2890303002aa0720274d3
3
+ metadata.gz: 06d8c511378ca4a23050ca5a6e1d65b8d78fda5f8104cb52da5619455e6dbfa2
4
+ data.tar.gz: 5587938b2ff4536214f5e159e6eecf04318c03aaaeaff0fd3cbe1dbd19740daf
5
5
  SHA512:
6
- metadata.gz: d47764a549b16704b6672bed22add68438e0ef42be86f97a0d71dc2d3dbb8b371b96b1e120402ca2f9c3631ab57134dcf9341540b669bcdc7dcea11174a20336
7
- data.tar.gz: 22e80353033d4b57d754a3b48b5515370cc1512a134bb534897c0e75cdcf72a3f1fe5444cc9e724aa6ac57bc6996ab825426547a513ebe4eb264cbecd03f354d
6
+ metadata.gz: e56fb78bdcee718e5c7543d6a0e6c5af6a45b739319f9ddaaf1dd233894b196b8bb4ea8d3442af2d4918f73e96d73ff78ebfbbc394da964e05078ab8375c012e
7
+ data.tar.gz: b673fbe4caa5e9bdd30868aac90d1fed5d146cbdc2ee6e2eb42da8b59ad53e38feaa66052b04fa0e2eb90b0889f866f3c61a635545168955c35e861d5bba9c91
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: macos
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-macos:
9
13
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
14
  runs-on: macos-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -20,7 +25,7 @@ jobs:
20
25
  architecture: 'x64'
21
26
  - name: Update gems
22
27
  run: |
23
- sudo gem install bundler -v "~> 2" --force
28
+ sudo gem install bundler --force
24
29
  bundle install --jobs 4 --retry 3
25
30
  - name: Run specs
26
31
  run: |
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: ubuntu
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-linux:
9
13
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
14
  runs-on: ubuntu-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -20,7 +25,7 @@ jobs:
20
25
  architecture: 'x64'
21
26
  - name: Update gems
22
27
  run: |
23
- gem install bundler -v "~> 2"
28
+ gem install bundler
24
29
  bundle install --jobs 4 --retry 3
25
30
  - name: Run specs
26
31
  run: |
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: windows
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-windows:
9
13
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
14
  runs-on: windows-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -21,7 +26,7 @@ jobs:
21
26
  - name: Update gems
22
27
  shell: pwsh
23
28
  run: |
24
- gem install bundler -v "~> 2"
29
+ gem install bundler
25
30
  bundle config --local path vendor/bundle
26
31
  bundle update
27
32
  bundle install --jobs 4 --retry 3
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  .rspec_status
14
14
  pubs-export.json
15
15
  Gemfile.lock
16
+ .byebug_history
@@ -9,17 +9,12 @@ module RelatonNist
9
9
  ret = super
10
10
  return if ret.nil?
11
11
 
12
- keyword_hash_to_bib(ret)
13
12
  commentperiod_hash_to_bib(ret)
14
13
  ret
15
14
  end
16
15
 
17
16
  private
18
17
 
19
- def keyword_hash_to_bib(ret)
20
- ret[:keyword]&.map! { |kw| Keyword.new kw }
21
- end
22
-
23
18
  def commentperiod_hash_to_bib(ret)
24
19
  return unless ret[:commentperiod]
25
20
 
@@ -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
@@ -16,17 +13,18 @@ module RelatonNist
16
13
  def sort_value
17
14
  @sort_value ||= begin
18
15
  sort_phrase = [hit[:serie], hit[:code], hit[:title]].join " "
19
- corr = hit_collection.text.split.map do |w|
16
+ corr = hit_collection&.text&.split&.map do |w|
20
17
  if w =~ /\w+/ &&
21
18
  sort_phrase =~ Regexp.new(Regexp.escape(w), Regexp::IGNORECASE)
22
19
  1
23
20
  else 0
24
21
  end
25
- end.sum
22
+ end&.sum.to_i
26
23
  corr + case hit[:status]
27
- when "final" then 3
28
- when "withdrawn" then 2
29
- when "draft (withdrawn)" then 1
24
+ when "final" then 4
25
+ when "withdrawn" then 3
26
+ when "draft" then 2
27
+ when "draft (obsolete)" then 1
30
28
  else 0
31
29
  end
32
30
  end
@@ -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
 
@@ -66,12 +60,12 @@ module RelatonNist
66
60
  serie = h.at("td[1]").text.strip
67
61
  code = h.at("td[2]").text.strip
68
62
  title = link.text
69
- url = DOMAIN + link[:href]
63
+ doc_url = DOMAIN + link[:href]
70
64
  status = h.at("td[4]").text.strip.downcase
71
65
  release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y"
72
66
  Hit.new(
73
67
  {
74
- code: code, serie: serie, title: title, url: url, status: status,
68
+ code: code, serie: serie, title: title, url: doc_url, status: status,
75
69
  release_date: release_date
76
70
  }, self
77
71
  )
@@ -4,7 +4,7 @@ module RelatonNist
4
4
  attr_reader :doctype
5
5
 
6
6
  # @return [Array<RelatonNist::Keyword>]
7
- attr_reader :keyword
7
+ # attr_reader :keyword
8
8
 
9
9
  # @return [RelatonNist::CommentPeriod, NilClass]
10
10
  attr_reader :commentperiod
@@ -57,7 +57,7 @@ module RelatonNist
57
57
  # @option relation [Array<RelatonBib::BibItemLocality>] :bib_locality
58
58
  def initialize(**args)
59
59
  @doctype = args.delete(:doctype) || "standard"
60
- @keyword = args.delete(:keyword) || []
60
+ # @keyword = args.delete(:keyword) || []
61
61
  @commentperiod = args.delete :commentperiod
62
62
  super
63
63
  end
@@ -78,7 +78,7 @@ module RelatonNist
78
78
  # @return [Hash]
79
79
  def to_hash
80
80
  hash = super
81
- hash["keyword"] = single_element_array(keyword) if keyword&.any?
81
+ # hash["keyword"] = single_element_array(keyword) if keyword&.any?
82
82
  hash["commentperiod"] = commentperiod.to_hash if commentperiod
83
83
  hash
84
84
  end
@@ -3,7 +3,6 @@ require "relaton_nist/nist_bibliographic_item"
3
3
  require "relaton_nist/scrapper"
4
4
  require "relaton_nist/hit_collection"
5
5
  require "relaton_nist/xml_parser"
6
- require "relaton_nist/keyword"
7
6
  require "relaton_nist/comment_period"
8
7
  require "relaton_nist/document_status"
9
8
  require "relaton_nist/hash_converter"
@@ -87,7 +87,12 @@ module RelatonNist
87
87
  # @return [Array<Nokogiri::HTML::Document, String>]
88
88
  def get_page(url)
89
89
  uri = URI url
90
- resp = Net::HTTP.get_response(uri) # .encode("UTF-8")
90
+ resp = Net::HTTP.get_response(uri)
91
+ %r{(?<=newLocation = 'https://' \+ window.location.hostname \+ ')(?<path>[^']+)} =~ resp.body
92
+ if path
93
+ uri = URI HitCollection::DOMAIN + path
94
+ resp = Net::HTTP.get_response(uri)
95
+ end
91
96
  Nokogiri::HTML(resp.body)
92
97
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
93
98
  Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
@@ -104,7 +109,7 @@ module RelatonNist
104
109
  else
105
110
  doc.at(
106
111
  "//div[contains(@class, 'publications-detail')]/h3",
107
- )&.text&.strip
112
+ )&.text&.strip.sub(/(?<=\w)\([^\)]+\)$/) { |m| " " + m.upcase}.squeeze " "
108
113
  end
109
114
  item_ref ||= "?"
110
115
  [RelatonBib::DocumentIdentifier.new(id: item_ref, type: "NIST")]
@@ -129,7 +134,7 @@ module RelatonNist
129
134
  iter = doc["iteration"] == "initial" ? 1 : doc["iteration"]
130
135
  else
131
136
  case status
132
- when "draft (withdrawn)"
137
+ when "draft (obsolete)"
133
138
  stage = "draft-public"
134
139
  subst = "withdrawn"
135
140
  when "retired draft"
@@ -138,7 +143,7 @@ module RelatonNist
138
143
  when "withdrawn"
139
144
  stage = "final"
140
145
  subst = "withdrawn"
141
- when "draft"
146
+ when /^draft/
142
147
  stage = "draft-public"
143
148
  subst = "active"
144
149
  else
@@ -352,9 +357,9 @@ module RelatonNist
352
357
  links << { type: "uri", content: doc["uri"] } if doc["uri"]
353
358
  doi = "https://doi.org/" + doc["doi"] if doc["doi"]
354
359
  else
355
- pub = doc.at "//p/strong[.='Publication:']"
356
- pdf = pub.at "./following-sibling::a[.=' Local Download']"
357
- doi = pub.at("./following-sibling::a[contains(.,'(DOI)')]")&.attr :href
360
+ pub = doc.at "//p/strong[contains(., 'Publication:')]"
361
+ pdf = pub&.at "./following-sibling::a[.=' Local Download']"
362
+ doi = pub&.at("./following-sibling::a[contains(.,'(DOI)')]")&.attr :href
358
363
  links << { type: "pdf", content: pdf[:href] } if pdf
359
364
  end
360
365
  links << { type: "doi", content: doi } if doi
@@ -417,10 +422,12 @@ module RelatonNist
417
422
  else idx + 1
418
423
  end
419
424
 
420
- content = s.text.match(/^[^\(]+/).to_s.strip.gsub " ", " "
425
+ content = s.text.match(/^[^\(]+/).to_s.strip.squeeze " "
421
426
 
422
- ref = case content.match(/\w+/).to_s
423
- when "Draft" then content.match(/(?<=Draft\s).+/).to_s + " (#{iter}PD)"
427
+ ref = case s.text
428
+ when /^Draft/ then content.match(/(?<=Draft\s).+/).to_s + " (#{iter}PD)"
429
+ when /\(Draft\)/ then content + " (#{iter}PD)"
430
+ else content
424
431
  end
425
432
 
426
433
  fref = RelatonBib::FormattedRef.new(
@@ -438,7 +445,7 @@ module RelatonNist
438
445
  else
439
446
  doc.xpath "//span[@id='pub-keywords-container']/span"
440
447
  end
441
- kws.map { |kw| Keyword.new kw.is_a?(String) ? kw : kw.text }
448
+ kws.map { |kw| kw.is_a?(String) ? kw : kw.text }
442
449
  end
443
450
 
444
451
  # @param doc [Nokogiri::HTML::Document]
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.8.1".freeze
3
3
  end
@@ -4,7 +4,11 @@ module RelatonNist
4
4
  def from_xml(xml)
5
5
  doc = Nokogiri::XML xml
6
6
  nistitem = doc.at("/bibitem|/bibdata")
7
- NistBibliographicItem.new(item_data(nistitem))
7
+ if nistitem
8
+ NistBibliographicItem.new(item_data(nistitem))
9
+ elsif
10
+ warn "[relato-nist] can't find bibitem or bibdata element in the XML"
11
+ end
8
12
  end
9
13
 
10
14
  private
@@ -14,7 +18,6 @@ module RelatonNist
14
18
  ext = nistitem.at "./ext"
15
19
  return data unless ext
16
20
 
17
- data[:keyword] = fetch_keyword(ext)
18
21
  data[:commentperiod] = fetch_commentperiod(ext)
19
22
  data
20
23
  end
@@ -39,12 +42,6 @@ module RelatonNist
39
42
  extended: cp.at("extended")&.text
40
43
  )
41
44
  end
42
-
43
- def fetch_keyword(item)
44
- item.xpath("./keyword").map do |kw|
45
- Keyword.new kw.children.first.to_xml
46
- end
47
- end
48
45
  end
49
46
  end
50
47
  end
data/relaton_nist.gemspec CHANGED
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "webmock"
36
36
  spec.add_development_dependency "ruby-jing"
37
37
 
38
- spec.add_dependency "relaton-bib", "~> 0.5.0"
38
+ spec.add_dependency "relaton-bib", "~> 0.8.0"
39
39
  spec.add_dependency "rubyzip"
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.8.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-01-11 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.5.0
173
+ version: 0.8.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: 0.5.0
180
+ version: 0.8.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubyzip
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -223,7 +223,6 @@ files:
223
223
  - lib/relaton_nist/hash_converter.rb
224
224
  - lib/relaton_nist/hit.rb
225
225
  - lib/relaton_nist/hit_collection.rb
226
- - lib/relaton_nist/keyword.rb
227
226
  - lib/relaton_nist/nist_bibliographic_item.rb
228
227
  - lib/relaton_nist/nist_bibliography.rb
229
228
  - lib/relaton_nist/processor.rb
@@ -1,23 +0,0 @@
1
- module RelatonNist
2
- class Keyword
3
- include RelatonBib
4
-
5
- # @return [Nokogiri::XML::DocumentFragment]
6
- attr_reader :element
7
-
8
- # @param element [String]
9
- def initialize(element)
10
- @element = Nokogiri::XML.fragment element
11
- end
12
-
13
- # @param builder [Nokogiri::XML::Builder]
14
- def to_xml(builder)
15
- builder.keyword element.to_xml
16
- end
17
-
18
- # @return [String]
19
- def to_hash
20
- element.text
21
- end
22
- end
23
- end