relaton-nist 0.3.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -66,12 +66,12 @@ module RelatonNist
66
66
  serie = h.at("td[1]").text.strip
67
67
  code = h.at("td[2]").text.strip
68
68
  title = link.text
69
- url = DOMAIN + link[:href]
69
+ doc_url = DOMAIN + link[:href]
70
70
  status = h.at("td[4]").text.strip.downcase
71
71
  release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y"
72
72
  Hit.new(
73
73
  {
74
- code: code, serie: serie, title: title, url: url, status: status,
74
+ code: code, serie: serie, title: title, url: doc_url, status: status,
75
75
  release_date: release_date
76
76
  }, self
77
77
  )
@@ -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
@@ -68,7 +68,7 @@ module RelatonNist
68
68
  if opts[:bibdata]
69
69
  b.ext do
70
70
  b.doctype doctype
71
- keyword.each { |kw| kw.to_xml b }
71
+ # keyword.each { |kw| kw.to_xml b }
72
72
  commentperiod&.to_xml b
73
73
  end
74
74
  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"
@@ -29,6 +28,8 @@ module RelatonNist
29
28
  #
30
29
  # @return [String] Relaton XML serialisation of reference
31
30
  def get(code, year = nil, opts = {})
31
+ return fetch_ref_err(code, year, []) if code =~ /\sEP$/
32
+
32
33
  /^(?<code2>[^\(]+)(\((?<date2>\w+\s(\d{2},\s)?\d{4})\))?\s?\(?((?<=\()(?<stage>[^\)]+))?/ =~ code
33
34
  if code2
34
35
  code = code2.strip
@@ -5,7 +5,7 @@ module RelatonNist
5
5
  def initialize
6
6
  @short = :relaton_nist
7
7
  @prefix = "NIST"
8
- @defaultprefix = %r{^(NIST|NISTGCR|ITL Bulletin|JPCRD|NISTIR|CSRC)(/[^\s])?\s}
8
+ @defaultprefix = %r{^(NIST|NISTGCR|ITL Bulletin|JPCRD|NISTIR|CSRC|FIPS)(/[^\s])?\s}
9
9
  @idtype = "NIST"
10
10
  end
11
11
 
@@ -29,5 +29,11 @@ module RelatonNist
29
29
  item_hash = ::RelatonNist::HashConverter.hash_to_bib(hash)
30
30
  ::RelatonNist::NistBibliographicItem.new item_hash
31
31
  end
32
+
33
+ # Returns hash of XML grammar
34
+ # @return [String]
35
+ def grammar_hash
36
+ @grammar_hash ||= ::RelatonNist.grammar_hash
37
+ end
32
38
  end
33
39
  end
@@ -27,7 +27,7 @@ module RelatonNist
27
27
  item_data[:fetched] = Date.today.to_s
28
28
  item_data[:type] = "standard"
29
29
  item_data[:title] = titles
30
- item_data[:doctype] = doctype
30
+ item_data[:doctype] = "standard" # doctype
31
31
 
32
32
  NistBibliographicItem.new(**item_data)
33
33
  end
@@ -47,6 +47,7 @@ module RelatonNist
47
47
  docstatus: fetch_status(json, hit_data[:status]),
48
48
  copyright: fetch_copyright(json["published-date"]),
49
49
  relation: fetch_relations_json(json),
50
+ place: ["Gaithersburg, MD"],
50
51
  keyword: fetch_keywords(json),
51
52
  commentperiod: fetch_commentperiod_json(json),
52
53
  }
@@ -86,7 +87,12 @@ module RelatonNist
86
87
  # @return [Array<Nokogiri::HTML::Document, String>]
87
88
  def get_page(url)
88
89
  uri = URI url
89
- 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
90
96
  Nokogiri::HTML(resp.body)
91
97
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
92
98
  Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
@@ -103,7 +109,7 @@ module RelatonNist
103
109
  else
104
110
  doc.at(
105
111
  "//div[contains(@class, 'publications-detail')]/h3",
106
- )&.text&.strip
112
+ )&.text&.strip.sub(/(?<=\w)\([^\)]+\)$/) { |m| " " + m.upcase}.squeeze " "
107
113
  end
108
114
  item_ref ||= "?"
109
115
  [RelatonBib::DocumentIdentifier.new(id: item_ref, type: "NIST")]
@@ -128,7 +134,7 @@ module RelatonNist
128
134
  iter = doc["iteration"] == "initial" ? 1 : doc["iteration"]
129
135
  else
130
136
  case status
131
- when "draft (withdrawn)"
137
+ when "draft (obsolete)"
132
138
  stage = "draft-public"
133
139
  subst = "withdrawn"
134
140
  when "retired draft"
@@ -137,7 +143,7 @@ module RelatonNist
137
143
  when "withdrawn"
138
144
  stage = "final"
139
145
  subst = "withdrawn"
140
- when "draft"
146
+ when /^draft/
141
147
  stage = "draft-public"
142
148
  subst = "active"
143
149
  else
@@ -351,9 +357,9 @@ module RelatonNist
351
357
  links << { type: "uri", content: doc["uri"] } if doc["uri"]
352
358
  doi = "https://doi.org/" + doc["doi"] if doc["doi"]
353
359
  else
354
- pub = doc.at "//p/strong[.='Publication:']"
355
- pdf = pub.at "./following-sibling::a[.=' Local Download']"
356
- 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
357
363
  links << { type: "pdf", content: pdf[:href] } if pdf
358
364
  end
359
365
  links << { type: "doi", content: doi } if doi
@@ -416,10 +422,12 @@ module RelatonNist
416
422
  else idx + 1
417
423
  end
418
424
 
419
- content = s.text.match(/^[^\(]+/).to_s.strip.gsub " ", " "
425
+ content = s.text.match(/^[^\(]+/).to_s.strip.squeeze " "
420
426
 
421
- ref = case content.match(/\w+/).to_s
422
- 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
423
431
  end
424
432
 
425
433
  fref = RelatonBib::FormattedRef.new(
@@ -437,7 +445,7 @@ module RelatonNist
437
445
  else
438
446
  doc.xpath "//span[@id='pub-keywords-container']/span"
439
447
  end
440
- kws.map { |kw| Keyword.new kw.is_a?(String) ? kw : kw.text }
448
+ kws.map { |kw| kw.is_a?(String) ? kw : kw.text }
441
449
  end
442
450
 
443
451
  # @param doc [Nokogiri::HTML::Document]
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "0.3.9".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -14,7 +14,6 @@ module RelatonNist
14
14
  ext = nistitem.at "./ext"
15
15
  return data unless ext
16
16
 
17
- data[:keyword] = fetch_keyword(ext)
18
17
  data[:commentperiod] = fetch_commentperiod(ext)
19
18
  data
20
19
  end
@@ -39,12 +38,6 @@ module RelatonNist
39
38
  extended: cp.at("extended")&.text
40
39
  )
41
40
  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
41
  end
49
42
  end
50
43
  end
data/relaton_nist.gemspec CHANGED
@@ -23,7 +23,6 @@ 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 "bundler", "~> 2.0"
27
26
  spec.add_development_dependency "byebug"
28
27
  spec.add_development_dependency "debase"
29
28
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -34,7 +33,8 @@ Gem::Specification.new do |spec|
34
33
  spec.add_development_dependency "simplecov"
35
34
  spec.add_development_dependency "vcr"
36
35
  spec.add_development_dependency "webmock"
36
+ spec.add_development_dependency "ruby-jing"
37
37
 
38
- spec.add_dependency "relaton-bib", "~> 0.3.0"
38
+ spec.add_dependency "relaton-bib", "~> 0.6.0"
39
39
  spec.add_dependency "rubyzip"
40
40
  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.3.9
4
+ version: 0.6.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: 2019-12-02 00:00:00.000000000 Z
11
+ date: 2020-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: byebug
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +150,34 @@ dependencies:
164
150
  - - ">="
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: ruby-jing
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: relaton-bib
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.3.0
173
+ version: 0.6.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.3.0
180
+ version: 0.6.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubyzip
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -206,19 +206,23 @@ files:
206
206
  - ".rspec"
207
207
  - ".rubocop.yml"
208
208
  - Gemfile
209
- - Gemfile.lock
210
209
  - LICENSE.txt
211
210
  - README.adoc
212
211
  - Rakefile
213
212
  - bin/console
214
213
  - bin/setup
214
+ - grammars/basicdoc.rng
215
+ - grammars/biblio.rng
216
+ - grammars/isodoc.rng
217
+ - grammars/isostandard.rng
218
+ - grammars/nist.rng
219
+ - grammars/reqt.rng
215
220
  - lib/relaton_nist.rb
216
221
  - lib/relaton_nist/comment_period.rb
217
222
  - lib/relaton_nist/document_status.rb
218
223
  - lib/relaton_nist/hash_converter.rb
219
224
  - lib/relaton_nist/hit.rb
220
225
  - lib/relaton_nist/hit_collection.rb
221
- - lib/relaton_nist/keyword.rb
222
226
  - lib/relaton_nist/nist_bibliographic_item.rb
223
227
  - lib/relaton_nist/nist_bibliography.rb
224
228
  - lib/relaton_nist/processor.rb
data/Gemfile.lock DELETED
@@ -1,87 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- relaton-nist (0.3.9)
5
- relaton-bib (~> 0.3.0)
6
- rubyzip
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- byebug (11.0.1)
14
- coderay (1.1.2)
15
- crack (0.4.3)
16
- safe_yaml (~> 1.0.0)
17
- debase (0.2.2)
18
- debase-ruby_core_source (>= 0.10.2)
19
- debase-ruby_core_source (0.10.5)
20
- diff-lcs (1.3)
21
- docile (1.3.2)
22
- equivalent-xml (0.6.0)
23
- nokogiri (>= 1.4.3)
24
- hashdiff (0.4.0)
25
- json (2.2.0)
26
- method_source (0.9.2)
27
- mini_portile2 (2.4.0)
28
- nokogiri (1.10.4)
29
- mini_portile2 (~> 2.4.0)
30
- pry (0.12.2)
31
- coderay (~> 1.1.0)
32
- method_source (~> 0.9.0)
33
- pry-byebug (3.7.0)
34
- byebug (~> 11.0)
35
- pry (~> 0.10)
36
- public_suffix (4.0.1)
37
- rake (10.5.0)
38
- relaton-bib (0.3.12)
39
- addressable
40
- nokogiri
41
- rspec (3.8.0)
42
- rspec-core (~> 3.8.0)
43
- rspec-expectations (~> 3.8.0)
44
- rspec-mocks (~> 3.8.0)
45
- rspec-core (3.8.1)
46
- rspec-support (~> 3.8.0)
47
- rspec-expectations (3.8.4)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.8.0)
50
- rspec-mocks (3.8.1)
51
- diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.8.0)
53
- rspec-support (3.8.2)
54
- ruby-debug-ide (0.7.0)
55
- rake (>= 0.8.1)
56
- rubyzip (2.0.0)
57
- safe_yaml (1.0.5)
58
- simplecov (0.16.1)
59
- docile (~> 1.1)
60
- json (>= 1.8, < 3)
61
- simplecov-html (~> 0.10.0)
62
- simplecov-html (0.10.2)
63
- vcr (5.0.0)
64
- webmock (3.6.0)
65
- addressable (>= 2.3.6)
66
- crack (>= 0.3.2)
67
- hashdiff (>= 0.4.0, < 2.0.0)
68
-
69
- PLATFORMS
70
- ruby
71
-
72
- DEPENDENCIES
73
- bundler (~> 2.0)
74
- byebug
75
- debase
76
- equivalent-xml (~> 0.6)
77
- pry-byebug
78
- rake (~> 10.0)
79
- relaton-nist!
80
- rspec (~> 3.0)
81
- ruby-debug-ide
82
- simplecov
83
- vcr
84
- webmock
85
-
86
- BUNDLED WITH
87
- 2.0.2
@@ -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