relaton-ietf 1.7.3 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/reqt.rng CHANGED
@@ -30,15 +30,34 @@
30
30
  <data type="boolean"/>
31
31
  </attribute>
32
32
  </optional>
33
+ <optional>
34
+ <attribute name="number"/>
35
+ </optional>
33
36
  <optional>
34
37
  <attribute name="subsequence"/>
35
38
  </optional>
39
+ <optional>
40
+ <attribute name="keep-with-next">
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ <optional>
45
+ <attribute name="keep-lines-together">
46
+ <data type="boolean"/>
47
+ </attribute>
48
+ </optional>
36
49
  <attribute name="id">
37
50
  <data type="ID"/>
38
51
  </attribute>
39
52
  <optional>
40
53
  <attribute name="filename"/>
41
54
  </optional>
55
+ <optional>
56
+ <attribute name="model"/>
57
+ </optional>
58
+ <optional>
59
+ <attribute name="type"/>
60
+ </optional>
42
61
  <optional>
43
62
  <ref name="reqtitle"/>
44
63
  </optional>
@@ -48,9 +67,9 @@
48
67
  <optional>
49
68
  <ref name="subject"/>
50
69
  </optional>
51
- <optional>
70
+ <zeroOrMore>
52
71
  <ref name="reqinherit"/>
53
- </optional>
72
+ </zeroOrMore>
54
73
  <zeroOrMore>
55
74
  <ref name="classification"/>
56
75
  </zeroOrMore>
@@ -135,6 +154,16 @@
135
154
  <data type="boolean"/>
136
155
  </attribute>
137
156
  </optional>
157
+ <optional>
158
+ <attribute name="keep-with-next">
159
+ <data type="boolean"/>
160
+ </attribute>
161
+ </optional>
162
+ <optional>
163
+ <attribute name="keep-lines-together">
164
+ <data type="boolean"/>
165
+ </attribute>
166
+ </optional>
138
167
  <oneOrMore>
139
168
  <ref name="BasicBlock"/>
140
169
  </oneOrMore>
@@ -5,7 +5,7 @@ module RelatonIetf
5
5
  # Ovverides superclass's method
6
6
  #
7
7
  # @param item [Hash]
8
- # @retirn [RelatonIec::IecBibliographicItem]
8
+ # @retirn [RelatonIetf::IetfBibliographicItem]
9
9
  def bib_item(item)
10
10
  IetfBibliographicItem.new(**item)
11
11
  end
@@ -17,6 +17,13 @@ module RelatonIetf
17
17
  super
18
18
  end
19
19
 
20
+ # @param hash [Hash]
21
+ # @return [RelatonIetf::IetfBibliographicItem]
22
+ def self.from_hash(hash)
23
+ item_hash = ::RelatonIetf::HashConverter.hash_to_bib(hash)
24
+ new **item_hash
25
+ end
26
+
20
27
  # @param opts [Hash]
21
28
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
22
29
  # @option opts [Boolean] :bibdata
@@ -20,7 +20,11 @@ module RelatonIetf
20
20
  def get(code, _year = nil, _opts = {})
21
21
  warn "[relaton-ietf] (\"#{code}\") fetching..."
22
22
  result = search code
23
- warn "[relaton-ietf] (\"#{code}\") found #{result.docidentifier.first.id}"
23
+ if result
24
+ warn "[relaton-ietf] (\"#{code}\") found #{result.docidentifier.first.id}"
25
+ else
26
+ warn "[relaton-ietf] (\"#{code}\") not found"
27
+ end
24
28
  result
25
29
  end
26
30
  end
@@ -27,8 +27,7 @@ module RelatonIetf
27
27
  # @param hash [Hash]
28
28
  # @return [RelatonIetf::IetfBibliographicItem]
29
29
  def hash_to_bib(hash)
30
- item_hash = ::RelatonIetf::HashConverter.hash_to_bib(hash)
31
- ::RelatonIetf::IetfBibliographicItem.new item_hash
30
+ ::RelatonIetf::IetfBibliographicItem.from_hash hash
32
31
  end
33
32
 
34
33
  # Returns hash of XML grammar
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "net/http"
4
- require "nokogiri"
5
4
  require "relaton_bib"
6
5
  require "relaton_ietf/ietf_bibliographic_item"
7
6
 
@@ -17,16 +16,16 @@ module RelatonIetf
17
16
  # @param text [String]
18
17
  # @param is_relation [TrueClass, FalseClass]
19
18
  # @return [RelatonIetf::IetfBibliographicItem]
20
- def scrape_page(text, is_relation = false)
19
+ def scrape_page(text, is_relation: false)
21
20
  # Remove initial "IETF " string if specified
22
21
  ref = text.gsub(/^IETF /, "")
23
- /^(RFC|BCP|FYI|STD)\s(?<num>\d+)/ =~ ref
22
+ /^(?:RFC|BCP|FYI|STD)\s(?<num>\d+)/ =~ ref
24
23
  ref.sub! /(?<=^(?:RFC|BCP|FYI|STD)\s)(\d+)/, num.rjust(4, "0") if num
25
24
  rfc_item ref, is_relation
26
25
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
27
26
  Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
28
27
  Net::ProtocolError, SocketError
29
- raise RelatonBib::RequestError, "No document found for #{ref} reference."
28
+ raise RelatonBib::RequestError, "No document found for #{ref} reference"
30
29
  end
31
30
 
32
31
  # @param reference [Nokogiri::XML::Element, nil]
@@ -34,7 +33,7 @@ module RelatonIetf
34
33
  # @param url [String, NilClass]
35
34
  # @param ver [String, NilClass] Internet Draft version
36
35
  # @return [RelatonIetf::IetfBibliographicItem]
37
- def fetch_rfc(reference, is_relation = false, url = nil, ver = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
36
+ def fetch_rfc(reference, is_relation: false, url: nil, ver: nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
38
37
  return unless reference
39
38
 
40
39
  ietf_item(
@@ -54,7 +53,7 @@ module RelatonIetf
54
53
  series: series(reference),
55
54
  place: ["Fremont, CA"],
56
55
  keyword: reference.xpath("front/keyword").map(&:text),
57
- doctype: doctype(reference[:anchor])
56
+ doctype: doctype(reference[:anchor]),
58
57
  )
59
58
  end
60
59
 
@@ -92,6 +91,7 @@ module RelatonIetf
92
91
  end
93
92
 
94
93
  # @param ref [String]
94
+ # @param is_relation [Boolen, nil]
95
95
  # @return [RelatonIetf::IetfBibliographicItem]
96
96
  def rfc_item(ref, is_relation)
97
97
  /(?<=-)(?<ver>\d{2})$/ =~ ref
@@ -102,14 +102,15 @@ module RelatonIetf
102
102
 
103
103
  uri = "#{GH_URL}#{ref.sub(/\s|\u00a0/, '.')}.xml"
104
104
  doc = Nokogiri::XML get_page(uri)
105
- fetch_rfc doc.at("/referencegroup", "/reference"), is_relation, uri, ver
105
+ r = doc.at("/referencegroup", "/reference")
106
+ fetch_rfc r, is_relation: is_relation, url: uri, ver: ver
106
107
  end
107
108
 
108
109
  # @param reference [Nokogiri::XML::Element]
109
110
  # @return [Hash]
110
111
  def relations(reference)
111
112
  reference.xpath("reference").map do |ref|
112
- { type: "includes", bibitem: fetch_rfc(ref, true) }
113
+ { type: "includes", bibitem: fetch_rfc(ref, is_relation: true) }
113
114
  end
114
115
  end
115
116
 
@@ -117,9 +118,10 @@ module RelatonIetf
117
118
  # @return [String] HTTP response body
118
119
  def get_page(uri)
119
120
  res = Net::HTTP.get_response(URI(uri))
120
- if res.code != "200"
121
- raise RelatonBib::RequestError, "No document found at #{uri}"
122
- end
121
+ return unless res.code == "200"
122
+
123
+ # raise RelatonBib::RequestError, "No document found at #{uri}"
124
+ # end
123
125
 
124
126
  res.body
125
127
  end
@@ -144,7 +146,11 @@ module RelatonIetf
144
146
  return if reference.at "./fornt/title"
145
147
 
146
148
  cont = (reference[:anchor] || reference[:docName] || reference[:number])
147
- RelatonBib::FormattedRef.new content: cont, language: language(reference), script: "Latn" if cont
149
+ if cont
150
+ RelatonBib::FormattedRef.new(
151
+ content: cont, language: language(reference), script: "Latn",
152
+ )
153
+ end
148
154
  end
149
155
 
150
156
  # @param reference [Nokogiri::XML::Element]
@@ -172,14 +178,15 @@ module RelatonIetf
172
178
  entity = RelatonBib::Person.new(
173
179
  name: full_name(author, reference),
174
180
  affiliation: [affiliation(author)],
175
- contact: contacts(author.at("./address"))
181
+ contact: contacts(author.at("./address")),
176
182
  )
177
183
  { entity: entity, role: [contributor_role(author)] }
178
184
  end
179
185
  end
180
186
 
181
187
  # @param reference [Nokogiri::XML::Element]
182
- # @return [Array<Hash{Symbol=>RelatonBib::Organization,Symbol=>Array<String>}>]
188
+ # @return [Array<Hash{Symbol=>RelatonBib::Organization,
189
+ # Symbol=>Array<String>}>]
183
190
  def organizations(reference)
184
191
  publisher = { entity: new_org, role: [type: "publisher"] }
185
192
  orgs = reference.xpath("./seriesinfo").reduce([publisher]) do |mem, si|
@@ -188,7 +195,7 @@ module RelatonIetf
188
195
  mem << { entity: new_org(si[:stream], nil), role: [type: "author"] }
189
196
  end
190
197
  orgs + reference.xpath(
191
- "front/author[not(@surname)][not(@fullname)]/organization"
198
+ "front/author[not(@surname)][not(@fullname)]/organization",
192
199
  ).map do |org|
193
200
  { entity: new_org(org.text, nil), role: [type: "author"] }
194
201
  end
@@ -202,7 +209,7 @@ module RelatonIetf
202
209
  RelatonBib::FullName.new(
203
210
  completename: localized_string(author[:fullname], lang),
204
211
  initial: [localized_string(author[:initials], lang)].compact,
205
- surname: localized_string(author[:surname], lang)
212
+ surname: localized_string(author[:surname], lang),
206
213
  )
207
214
  end
208
215
 
@@ -237,7 +244,7 @@ module RelatonIetf
237
244
  city: postal.at("./city")&.text,
238
245
  postcode: postal.at("./code")&.text,
239
246
  country: postal.at("./country")&.text,
240
- state: postal.at("./region")&.text
247
+ state: postal.at("./region")&.text,
241
248
  )
242
249
  end
243
250
 
@@ -309,7 +316,7 @@ module RelatonIetf
309
316
  ret = []
310
317
  if id
311
318
  ret << RelatonBib::DocumentIdentifier.new(
312
- type: "IETF", id: id.sub(/^(RFC)/, "\\1 ")
319
+ type: "IETF", id: id.sub(/^(RFC)/, "\\1 "),
313
320
  )
314
321
  end
315
322
  if (id = reference[:anchor])
@@ -336,10 +343,10 @@ module RelatonIetf
336
343
 
337
344
  RelatonBib::Series.new(
338
345
  title: RelatonBib::TypedTitleString.new(
339
- content: si[:name], language: language(reference), script: "Latn"
346
+ content: si[:name], language: language(reference), script: "Latn",
340
347
  ),
341
348
  number: si[:value],
342
- type: "main"
349
+ type: "main",
343
350
  )
344
351
  end.compact
345
352
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonIetf
2
- VERSION = "1.7.3".freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
data/relaton_ietf.gemspec CHANGED
@@ -27,18 +27,16 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
30
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
31
31
 
32
- # spec.add_development_dependency "debase"
33
32
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
34
33
  spec.add_development_dependency "pry-byebug"
35
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rake", "~> 13.0"
36
35
  spec.add_development_dependency "rspec", "~> 3.0"
37
- # spec.add_development_dependency "ruby-debug-ide"
38
36
  spec.add_development_dependency "ruby-jing"
39
37
  spec.add_development_dependency "simplecov"
40
38
  spec.add_development_dependency "vcr"
41
39
  spec.add_development_dependency "webmock"
42
40
 
43
- spec.add_dependency "relaton-bib", "~> 1.7.0"
41
+ spec.add_dependency "relaton-bib", "~> 1.9.0"
44
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.9.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: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.7.0
131
+ version: 1.9.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.7.0
138
+ version: 1.9.0
139
139
  description: "RelatonIetf: retrieve IETF Standards for bibliographic use \nusing the
140
140
  BibliographicItem model.\n\nFormerly known as rfcbib.\n"
141
141
  email:
@@ -183,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="
185
185
  - !ruby/object:Gem::Version
186
- version: 2.4.0
186
+ version: 2.5.0
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.0.6
193
+ rubygems_version: 3.2.3
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: 'RelatonIetf: retrieve IETF Standards for bibliographic use using the BibliographicItem