relaton-ietf 0.12.1 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -192,7 +192,8 @@ module RelatonIetf
192
192
 
193
193
  # @return [Array<Hash{Symbol=>RelatonBib::Person,Symbol=>Array<String>}>]
194
194
  def persons(reference)
195
- reference.xpath("./front/author").map do |author|
195
+ reference.xpath("./front/author[@surname]|./front/author[@fullname]").
196
+ map do |author|
196
197
  entity = RelatonBib::Person.new(
197
198
  name: full_name(author, reference),
198
199
  affiliation: [affiliation(author)],
@@ -204,29 +205,33 @@ module RelatonIetf
204
205
 
205
206
  # @return [Array<Hash{Symbol=>RelatonBib::Organization,Symbol=>Array<String>}>]
206
207
  def organizations(reference)
207
- reference.xpath("./seriesinfo").map do |si|
208
- next unless si[:stream]
208
+ publisher = { entity: new_org, role: [type: "publisher"] }
209
+ reference.xpath("./seriesinfo").reduce([publisher]) do |mem, si|
210
+ next mem unless si[:stream]
209
211
 
210
- entity = RelatonBib::Organization.new name: si[:stream]
211
- { entity: entity, role: [type: "author"] }
212
- end.compact
212
+ mem << { entity: new_org(si[:stream]), role: [type: "author"] }
213
+ end
213
214
  end
214
215
 
215
216
  # @param author [Nokogiri::XML::Document]
216
217
  # @param ref [Nokogiri::XML::Document]
217
218
  # @return [RelatonBib::FullName]
218
219
  def full_name(author, ref)
220
+ lang = language ref
219
221
  RelatonBib::FullName.new(
220
- completename: localized_string(author[:fullname], ref),
221
- initial: [localized_string(author[:initials], ref)],
222
- surname: [localized_string(author[:surname], ref)],
222
+ completename: localized_string(author[:fullname], lang),
223
+ initial: [localized_string(author[:initials], lang)].compact,
224
+ surname: localized_string(author[:surname], lang),
223
225
  )
224
226
  end
225
227
 
226
228
  # @param content [String]
229
+ # @param lang [String]
227
230
  # @return [RelatonBib::LocalizedString]
228
- def localized_string(content, ref)
229
- RelatonBib::LocalizedString.new(content, language(ref))
231
+ def localized_string(content, lang)
232
+ return unless content
233
+
234
+ RelatonBib::LocalizedString.new(content, lang)
230
235
  end
231
236
 
232
237
  # @param postal [Nokogiri::XML::Document]
@@ -267,13 +272,21 @@ module RelatonIetf
267
272
  # @return [RelatonBib::Affiliation]
268
273
  def affiliation(author)
269
274
  organization = author.at("./organization")
270
- org = RelatonBib::Organization.new(
271
- name: organization.nil? || organization.text.empty? ? "IETF" : organization.text,
272
- abbreviation: organization.nil? ? "IETF" : (organization[:abbrev] || "IETF"),
273
- )
275
+ org = if organization.nil? || organization&.text&.empty?
276
+ new_org
277
+ else
278
+ new_org organization.text, organization[:abbrev]
279
+ end
274
280
  RelatonBib::Affiliation.new organization: org
275
281
  end
276
282
 
283
+ # @param name [String]
284
+ # @param abbr [String]
285
+ # @return [RelatonBib::Organization]
286
+ def new_org(name = "Internet Engineering Task Force", abbr = "IETF")
287
+ RelatonBib::Organization.new name: name, abbreviation: abbr
288
+ end
289
+
277
290
  # @param author [Nokogiri::XML::Document]
278
291
  # @return [Hash]
279
292
  def contributor_role(author)
@@ -281,6 +294,7 @@ module RelatonIetf
281
294
  end
282
295
 
283
296
  def month(mon)
297
+ return 1 if !mon || mon.empty?
284
298
  return mon if /^\d+$/ =~ mon
285
299
 
286
300
  Date::MONTHNAMES.index(mon)
@@ -294,8 +308,8 @@ module RelatonIetf
294
308
  def dates(reference)
295
309
  return unless (date = reference.at "./front/date")
296
310
 
297
- d = [date[:year], month(date[:month]) || "01",
298
- (date[:day] || "01")].compact.join "-"
311
+ d = [date[:year], month(date[:month]),
312
+ (date[:day] || 1)].compact.join "-"
299
313
  date = Time.parse(d).strftime "%Y-%m-%d"
300
314
  [RelatonBib::BibliographicDate.new(type: "published", on: date)]
301
315
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonIetf
2
- VERSION = "0.12.1".freeze
2
+ VERSION = "1.0.4".freeze
3
3
  end
@@ -40,5 +40,5 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "vcr"
41
41
  spec.add_development_dependency "webmock"
42
42
 
43
- spec.add_dependency "relaton-bib", "~> 0.9.0"
43
+ spec.add_dependency "relaton-bib", ">= 1.0.4"
44
44
  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: 0.12.1
4
+ version: 1.0.4
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-03-31 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -154,16 +154,16 @@ dependencies:
154
154
  name: relaton-bib
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.9.0
159
+ version: 1.0.4
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: 0.9.0
166
+ version: 1.0.4
167
167
  description: "RelatonIetf: retrieve IETF Standards for bibliographic use \nusing the
168
168
  BibliographicItem model.\n\nFormerly known as rfcbib.\n"
169
169
  email: