relaton-bib 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -0
  3. data/.rubocop.yml +2 -2
  4. data/README.adoc +16 -0
  5. data/lib/relaton_bib.rb +2 -5
  6. data/lib/relaton_bib/bib_item_locality.rb +13 -1
  7. data/lib/relaton_bib/biblio_note.rb +11 -0
  8. data/lib/relaton_bib/biblio_version.rb +12 -0
  9. data/lib/relaton_bib/bibliographic_date.rb +13 -0
  10. data/lib/relaton_bib/bibliographic_item.rb +80 -24
  11. data/lib/relaton_bib/classification.rb +11 -0
  12. data/lib/relaton_bib/contribution_info.rb +27 -1
  13. data/lib/relaton_bib/contributor.rb +55 -1
  14. data/lib/relaton_bib/copyright_association.rb +14 -1
  15. data/lib/relaton_bib/document_identifier.rb +20 -4
  16. data/lib/relaton_bib/document_relation.rb +14 -4
  17. data/lib/relaton_bib/document_relation_collection.rb +12 -0
  18. data/lib/relaton_bib/document_status.rb +10 -0
  19. data/lib/relaton_bib/editorial_group.rb +9 -0
  20. data/lib/relaton_bib/formatted_ref.rb +7 -0
  21. data/lib/relaton_bib/formatted_string.rb +11 -0
  22. data/lib/relaton_bib/hash_converter.rb +38 -30
  23. data/lib/relaton_bib/ics.rb +11 -0
  24. data/lib/relaton_bib/localized_string.rb +23 -6
  25. data/lib/relaton_bib/medium.rb +11 -0
  26. data/lib/relaton_bib/organization.rb +27 -7
  27. data/lib/relaton_bib/person.rb +53 -7
  28. data/lib/relaton_bib/place.rb +13 -1
  29. data/lib/relaton_bib/series.rb +25 -4
  30. data/lib/relaton_bib/structured_identifier.rb +30 -0
  31. data/lib/relaton_bib/technical_committee.rb +11 -0
  32. data/lib/relaton_bib/typed_title_string.rb +13 -7
  33. data/lib/relaton_bib/typed_uri.rb +11 -0
  34. data/lib/relaton_bib/validity.rb +11 -0
  35. data/lib/relaton_bib/version.rb +1 -1
  36. data/lib/relaton_bib/workgroup.rb +10 -0
  37. data/lib/relaton_bib/xml_parser.rb +53 -38
  38. metadata +2 -2
@@ -10,7 +10,8 @@ module RelatonBib
10
10
  if bibitem
11
11
  bib_item item_data(bibitem)
12
12
  else
13
- warn "[relaton-bib] WARNING: can't find bibitem or bibdata element in the XML"
13
+ warn "[relaton-bib] WARNING: can't find bibitem or bibdata element "\
14
+ "in the XML"
14
15
  end
15
16
  end
16
17
 
@@ -19,7 +20,7 @@ module RelatonBib
19
20
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
20
21
 
21
22
  # @return [Hash]
22
- def item_data(bibitem)
23
+ def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity
23
24
  ext = bibitem.at "//ext"
24
25
  {
25
26
  id: bibitem[:id]&.empty? ? nil : bibitem[:id],
@@ -80,25 +81,28 @@ module RelatonBib
80
81
  type: n[:type],
81
82
  format: n[:format],
82
83
  language: n[:language],
83
- script: n[:script],
84
+ script: n[:script]
84
85
  )
85
86
  end
86
87
  end
87
88
 
88
89
  def fetch_language(item)
89
- item.xpath("./language").reduce([]) { |a, l| l.text.empty? ? a : a << l.text }
90
+ item.xpath("./language").reduce([]) do |a, l|
91
+ l.text.empty? ? a : a << l.text
92
+ end
90
93
  end
91
94
 
92
95
  def fetch_script(item)
93
- item.xpath("./script").reduce([]) { |a, s| s.text.empty? ? a : a << s.text }
96
+ item.xpath("./script").reduce([]) do |a, s|
97
+ s.text.empty? ? a : a << s.text
98
+ end
94
99
  end
95
100
 
96
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
97
-
98
- def fetch_series(item)
101
+ def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
99
102
  item.xpath("./series").reduce([]) do |mem, sr|
100
103
  abbr = sr.at "abbreviation"
101
- abbreviation = abbr ? LocalizedString.new(abbr.text, abbr[:language], abbr[:script]) : nil
104
+ abbreviation = abbr &&
105
+ LocalizedString.new(abbr.text, abbr[:language], abbr[:script])
102
106
  formattedref = fref(sr)
103
107
  title = ttitle(sr.at("title"))
104
108
  next mem unless formattedref || title
@@ -113,7 +117,6 @@ module RelatonBib
113
117
  )
114
118
  end
115
119
  end
116
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
117
120
 
118
121
  def fetch_medium(item)
119
122
  medium = item.at("./medium")
@@ -143,9 +146,12 @@ module RelatonBib
143
146
  vl = item.at("./validity")
144
147
  return unless vl
145
148
 
146
- begins = (b = vl.at("validityBegins")) ? Time.strptime(b.text, "%Y-%m-%d %H:%M") : nil
147
- ends = (e = vl.at("validityEnds")) ? Time.strptime(e.text, "%Y-%m-%d %H:%M") : nil
148
- revision = (r = vl.at("revision")) ? Time.strptime(r.text, "%Y-%m-%d %H:%M") : nil
149
+ begins = (b = vl.at("validityBegins")) &&
150
+ Time.strptime(b.text, "%Y-%m-%d %H:%M")
151
+ ends = (e = vl.at("validityEnds")) &&
152
+ Time.strptime(e.text, "%Y-%m-%d %H:%M")
153
+ revision = (r = vl.at("revision")) &&
154
+ Time.strptime(r.text, "%Y-%m-%d %H:%M")
149
155
  Validity.new begins: begins, ends: ends, revision: revision
150
156
  end
151
157
 
@@ -153,7 +159,8 @@ module RelatonBib
153
159
  # @return [Array<RelatonBib::DocumentIdentifier>]
154
160
  def fetch_docid(item)
155
161
  item.xpath("./docidentifier").map do |did|
156
- DocumentIdentifier.new(id: did.text, type: did[:type])
162
+ DocumentIdentifier.new(id: did.text, type: did[:type],
163
+ scope: did[:scope])
157
164
  end
158
165
  end
159
166
 
@@ -182,7 +189,7 @@ module RelatonBib
182
189
  DocumentStatus.new(
183
190
  stage: stg ? stage(stg) : status.text,
184
191
  substage: stage(status.at("substage")),
185
- iteration: status.at("iteration")&.text,
192
+ iteration: status.at("iteration")&.text
186
193
  )
187
194
  end
188
195
 
@@ -191,21 +198,24 @@ module RelatonBib
191
198
  def stage(elm)
192
199
  return unless elm
193
200
 
194
- DocumentStatus::Stage.new value: elm.text, abbreviation: elm[:abbreviation]
201
+ DocumentStatus::Stage.new(value: elm.text,
202
+ abbreviation: elm[:abbreviation])
195
203
  end
196
204
 
197
- def fetch_dates(item)
205
+ def fetch_dates(item) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
198
206
  item.xpath("./date").reduce([]) do |a, d|
199
207
  type = d[:type].to_s.empty? ? "published" : d[:type]
200
208
  if (on = d.at("on"))
201
- a << RelatonBib::BibliographicDate.new(type: type, on: on.text, to: d.at("to")&.text)
209
+ a << RelatonBib::BibliographicDate.new(type: type, on: on.text,
210
+ to: d.at("to")&.text)
202
211
  elsif (from = d.at("from"))
203
- a << RelatonBib::BibliographicDate.new(type: type, from: from.text, to: d.at("to")&.text)
212
+ a << RelatonBib::BibliographicDate.new(type: type, from: from.text,
213
+ to: d.at("to")&.text)
204
214
  end
205
215
  end
206
216
  end
207
217
 
208
- def get_org(org)
218
+ def get_org(org) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
209
219
  names = org.xpath("name").map do |n|
210
220
  { content: n.text, language: n[:language], script: n[:script] }
211
221
  end
@@ -219,7 +229,7 @@ module RelatonBib
219
229
  identifier: identifier)
220
230
  end
221
231
 
222
- def get_person(person)
232
+ def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
223
233
  affiliations = person.xpath("./affiliation").map do |a|
224
234
  org = a.at "./organization"
225
235
  desc = a.xpath("./description").map do |e|
@@ -229,7 +239,7 @@ module RelatonBib
229
239
  Affiliation.new organization: get_org(org), description: desc
230
240
  end
231
241
 
232
- contact = person.xpath("./address | ./phone | ./email | ./uri").map do |c|
242
+ contact = person.xpath("./address|./phone|./email|./uri").map do |c|
233
243
  if c.name == "address"
234
244
  streets = c.xpath("./street").map(&:text)
235
245
  Address.new(
@@ -237,7 +247,7 @@ module RelatonBib
237
247
  city: c.at("./city")&.text,
238
248
  state: c.at("./state")&.text,
239
249
  country: c.at("./country")&.text,
240
- postcode: c.at("./postcode")&.text,
250
+ postcode: c.at("./postcode")&.text
241
251
  )
242
252
  else
243
253
  Contact.new(type: c.name, value: c.text)
@@ -255,15 +265,17 @@ module RelatonBib
255
265
 
256
266
  name = FullName.new(
257
267
  completename: cname, surname: sname,
258
- initial: name_part(person, "initial"), forename: name_part(person, "forename"),
259
- addition: name_part(person, "addition"), prefix: name_part(person, "prefix")
268
+ initial: name_part(person, "initial"),
269
+ forename: name_part(person, "forename"),
270
+ addition: name_part(person, "addition"),
271
+ prefix: name_part(person, "prefix")
260
272
  )
261
273
 
262
274
  Person.new(
263
275
  name: name,
264
276
  affiliation: affiliations,
265
277
  contact: contact,
266
- identifier: identifier,
278
+ identifier: identifier
267
279
  )
268
280
  end
269
281
 
@@ -281,7 +293,8 @@ module RelatonBib
281
293
  elsif (person = c.at "./person") then get_person(person)
282
294
  end
283
295
  role = c.xpath("./role").map do |r|
284
- { type: r[:type], description: r.xpath("./description").map(&:text) }
296
+ { type: r[:type],
297
+ description: r.xpath("./description").map(&:text) }
285
298
  end
286
299
  ContributionInfo.new entity: entity, role: role
287
300
  end
@@ -320,15 +333,17 @@ module RelatonBib
320
333
  end
321
334
 
322
335
  # @param item [Nokogiri::XML::Element]
336
+ # @param klass [RelatonBib::DocumentRelation.class,
337
+ # RelatonNist::DocumentRelation.class]
323
338
  # @return [Array<RelatonBib::DocumentRelation>]
324
- def fetch_relations(item)
339
+ def fetch_relations(item, klass = DocumentRelation)
325
340
  item.xpath("./relation").map do |rel|
326
- DocumentRelation.new(
341
+ klass.new(
327
342
  type: rel[:type]&.empty? ? nil : rel[:type],
328
343
  description: relation_description(rel),
329
344
  bibitem: bib_item(item_data(rel.at("./bibitem"))),
330
345
  locality: localities(rel),
331
- source_locality: source_localities(rel),
346
+ source_locality: source_localities(rel)
332
347
  )
333
348
  end
334
349
  end
@@ -368,18 +383,21 @@ module RelatonBib
368
383
  klass.new(
369
384
  loc[:type],
370
385
  LocalizedString.new(loc.at("./referenceFrom").text),
371
- ref_to,
386
+ ref_to
372
387
  )
373
388
  end
374
389
 
375
390
  # @param rel [Nokogiri::XML::Element]
376
- # @return [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
391
+ # @return [Array<RelatonBib::SourceLocality,
392
+ # RelatonBib::SourceLocalityStack>]
377
393
  def source_localities(rel)
378
394
  rel.xpath("./sourceLocality|./sourceLocalityStack").map do |lc|
379
395
  if lc[:type]
380
396
  SourceLocalityStack.new [locality(lc, SourceLocality)]
381
397
  else
382
- sls = lc.xpath("./sourceLocality").map { |l| locality l, SourceLocality }
398
+ sls = lc.xpath("./sourceLocality").map do |l|
399
+ locality l, SourceLocality
400
+ end
383
401
  SourceLocalityStack.new sls
384
402
  end
385
403
  end
@@ -418,11 +436,9 @@ module RelatonBib
418
436
  end
419
437
  end
420
438
 
421
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
422
-
423
439
  # @param ext [Nokogiri::XML::Element]
424
440
  # @return [RelatonBib::StructuredIdentifierCollection]
425
- def fetch_structuredidentifier(ext)
441
+ def fetch_structuredidentifier(ext) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
426
442
  return unless ext
427
443
 
428
444
  sids = ext.xpath("structuredidentifier").map do |si|
@@ -437,12 +453,11 @@ module RelatonBib
437
453
  supplementtype: si.at("supplementtype")&.text,
438
454
  supplementnumber: si.at("supplementnumber")&.text,
439
455
  language: si.at("language")&.text,
440
- year: si.at("year")&.text,
456
+ year: si.at("year")&.text
441
457
  )
442
458
  end
443
459
  StructuredIdentifierCollection.new sids
444
460
  end
445
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
446
461
  end
447
462
  end
448
463
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.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: 2020-07-02 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug