relaton-bib 1.2.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) 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 +60 -18
  5. data/grammars/isodoc.rng +130 -21
  6. data/grammars/reqt.rng +2 -8
  7. data/lib/relaton_bib.rb +15 -15
  8. data/lib/relaton_bib/bib_item_locality.rb +13 -1
  9. data/lib/relaton_bib/biblio_note.rb +11 -0
  10. data/lib/relaton_bib/biblio_version.rb +12 -0
  11. data/lib/relaton_bib/bibliographic_date.rb +15 -1
  12. data/lib/relaton_bib/bibliographic_item.rb +93 -25
  13. data/lib/relaton_bib/classification.rb +11 -0
  14. data/lib/relaton_bib/contribution_info.rb +27 -1
  15. data/lib/relaton_bib/contributor.rb +55 -1
  16. data/lib/relaton_bib/copyright_association.rb +14 -1
  17. data/lib/relaton_bib/document_identifier.rb +49 -9
  18. data/lib/relaton_bib/document_relation.rb +14 -4
  19. data/lib/relaton_bib/document_relation_collection.rb +12 -0
  20. data/lib/relaton_bib/document_status.rb +10 -0
  21. data/lib/relaton_bib/editorial_group.rb +14 -0
  22. data/lib/relaton_bib/formatted_ref.rb +7 -0
  23. data/lib/relaton_bib/formatted_string.rb +11 -0
  24. data/lib/relaton_bib/hash_converter.rb +55 -36
  25. data/lib/relaton_bib/ics.rb +11 -0
  26. data/lib/relaton_bib/localized_string.rb +23 -6
  27. data/lib/relaton_bib/medium.rb +11 -0
  28. data/lib/relaton_bib/organization.rb +27 -7
  29. data/lib/relaton_bib/person.rb +54 -7
  30. data/lib/relaton_bib/place.rb +14 -2
  31. data/lib/relaton_bib/series.rb +25 -4
  32. data/lib/relaton_bib/structured_identifier.rb +30 -0
  33. data/lib/relaton_bib/technical_committee.rb +11 -0
  34. data/lib/relaton_bib/typed_title_string.rb +13 -7
  35. data/lib/relaton_bib/typed_uri.rb +11 -0
  36. data/lib/relaton_bib/validity.rb +11 -0
  37. data/lib/relaton_bib/version.rb +1 -1
  38. data/lib/relaton_bib/workgroup.rb +10 -0
  39. data/lib/relaton_bib/xml_parser.rb +55 -38
  40. metadata +5 -5
@@ -32,5 +32,16 @@ module RelatonBib
32
32
  hash["type"] = type.to_s if type
33
33
  hash
34
34
  end
35
+
36
+ # @param prefix [String]
37
+ # @param count [Integer] number of links
38
+ # @return [String]
39
+ def to_asciibib(prefix = "", count = 1)
40
+ pref = prefix.empty? ? "link" : prefix + ".link"
41
+ out = count > 1 ? "#{pref}::\n" : ""
42
+ out += "#{pref}.type:: #{type}\n" if type
43
+ out += "#{pref}.content:: #{content}\n"
44
+ out
45
+ end
35
46
  end
36
47
  end
@@ -37,5 +37,16 @@ module RelatonBib
37
37
  hash["revision"] = revision.strftime(FORMAT) if revision
38
38
  hash
39
39
  end
40
+
41
+ # @param prefix [String]
42
+ # @return [String]
43
+ def to_asciibib(prefix = "")
44
+ pref = prefix.empty? ? "validity." : prefix + ".validity."
45
+ out = ""
46
+ out += "#{pref}begins:: #{begins.strftime(FORMAT)}\n" if begins
47
+ out += "#{pref}ends:: #{ends.strftime(FORMAT)}\n" if ends
48
+ out += "#{pref}revision:: #{revision.strftime(FORMAT)}\n" if revision
49
+ out
50
+ end
40
51
  end
41
52
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.2.2".freeze
2
+ VERSION = "1.4.1".freeze
3
3
  end
@@ -32,5 +32,15 @@ module RelatonBib
32
32
  hash["type"] = type if type
33
33
  hash
34
34
  end
35
+
36
+ # @param prefix [String]
37
+ # @return [String]
38
+ def to_asciibib(prefix = "")
39
+ pref = prefix.empty? ? prefix : prefix + "."
40
+ out = "#{pref}content:: #{content}\n"
41
+ out += "#{pref}number:: #{number}\n" if number
42
+ out += "#{pref}type:: #{type}\n" if type
43
+ out
44
+ end
35
45
  end
36
46
  end
@@ -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,26 @@ 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
+ # @param node [Nokogiri::XML::Elemen]
206
+ # @return [Array<RelatonBib::BibliographicDate>]
207
+ def fetch_dates(item) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
198
208
  item.xpath("./date").reduce([]) do |a, d|
199
209
  type = d[:type].to_s.empty? ? "published" : d[:type]
200
210
  if (on = d.at("on"))
201
- a << RelatonBib::BibliographicDate.new(type: type, on: on.text, to: d.at("to")&.text)
211
+ a << RelatonBib::BibliographicDate.new(type: type, on: on.text,
212
+ to: d.at("to")&.text)
202
213
  elsif (from = d.at("from"))
203
- a << RelatonBib::BibliographicDate.new(type: type, from: from.text, to: d.at("to")&.text)
214
+ a << RelatonBib::BibliographicDate.new(type: type, from: from.text,
215
+ to: d.at("to")&.text)
204
216
  end
205
217
  end
206
218
  end
207
219
 
208
- def get_org(org)
220
+ def get_org(org) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
209
221
  names = org.xpath("name").map do |n|
210
222
  { content: n.text, language: n[:language], script: n[:script] }
211
223
  end
@@ -219,7 +231,7 @@ module RelatonBib
219
231
  identifier: identifier)
220
232
  end
221
233
 
222
- def get_person(person)
234
+ def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
223
235
  affiliations = person.xpath("./affiliation").map do |a|
224
236
  org = a.at "./organization"
225
237
  desc = a.xpath("./description").map do |e|
@@ -229,7 +241,7 @@ module RelatonBib
229
241
  Affiliation.new organization: get_org(org), description: desc
230
242
  end
231
243
 
232
- contact = person.xpath("./address | ./phone | ./email | ./uri").map do |c|
244
+ contact = person.xpath("./address|./phone|./email|./uri").map do |c|
233
245
  if c.name == "address"
234
246
  streets = c.xpath("./street").map(&:text)
235
247
  Address.new(
@@ -237,7 +249,7 @@ module RelatonBib
237
249
  city: c.at("./city")&.text,
238
250
  state: c.at("./state")&.text,
239
251
  country: c.at("./country")&.text,
240
- postcode: c.at("./postcode")&.text,
252
+ postcode: c.at("./postcode")&.text
241
253
  )
242
254
  else
243
255
  Contact.new(type: c.name, value: c.text)
@@ -255,15 +267,17 @@ module RelatonBib
255
267
 
256
268
  name = FullName.new(
257
269
  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")
270
+ initial: name_part(person, "initial"),
271
+ forename: name_part(person, "forename"),
272
+ addition: name_part(person, "addition"),
273
+ prefix: name_part(person, "prefix")
260
274
  )
261
275
 
262
276
  Person.new(
263
277
  name: name,
264
278
  affiliation: affiliations,
265
279
  contact: contact,
266
- identifier: identifier,
280
+ identifier: identifier
267
281
  )
268
282
  end
269
283
 
@@ -281,7 +295,8 @@ module RelatonBib
281
295
  elsif (person = c.at "./person") then get_person(person)
282
296
  end
283
297
  role = c.xpath("./role").map do |r|
284
- { type: r[:type], description: r.xpath("./description").map(&:text) }
298
+ { type: r[:type],
299
+ description: r.xpath("./description").map(&:text) }
285
300
  end
286
301
  ContributionInfo.new entity: entity, role: role
287
302
  end
@@ -320,15 +335,17 @@ module RelatonBib
320
335
  end
321
336
 
322
337
  # @param item [Nokogiri::XML::Element]
338
+ # @param klass [RelatonBib::DocumentRelation.class,
339
+ # RelatonNist::DocumentRelation.class]
323
340
  # @return [Array<RelatonBib::DocumentRelation>]
324
- def fetch_relations(item)
341
+ def fetch_relations(item, klass = DocumentRelation)
325
342
  item.xpath("./relation").map do |rel|
326
- DocumentRelation.new(
343
+ klass.new(
327
344
  type: rel[:type]&.empty? ? nil : rel[:type],
328
345
  description: relation_description(rel),
329
346
  bibitem: bib_item(item_data(rel.at("./bibitem"))),
330
347
  locality: localities(rel),
331
- source_locality: source_localities(rel),
348
+ source_locality: source_localities(rel)
332
349
  )
333
350
  end
334
351
  end
@@ -368,18 +385,21 @@ module RelatonBib
368
385
  klass.new(
369
386
  loc[:type],
370
387
  LocalizedString.new(loc.at("./referenceFrom").text),
371
- ref_to,
388
+ ref_to
372
389
  )
373
390
  end
374
391
 
375
392
  # @param rel [Nokogiri::XML::Element]
376
- # @return [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
393
+ # @return [Array<RelatonBib::SourceLocality,
394
+ # RelatonBib::SourceLocalityStack>]
377
395
  def source_localities(rel)
378
396
  rel.xpath("./sourceLocality|./sourceLocalityStack").map do |lc|
379
397
  if lc[:type]
380
398
  SourceLocalityStack.new [locality(lc, SourceLocality)]
381
399
  else
382
- sls = lc.xpath("./sourceLocality").map { |l| locality l, SourceLocality }
400
+ sls = lc.xpath("./sourceLocality").map do |l|
401
+ locality l, SourceLocality
402
+ end
383
403
  SourceLocalityStack.new sls
384
404
  end
385
405
  end
@@ -418,11 +438,9 @@ module RelatonBib
418
438
  end
419
439
  end
420
440
 
421
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
422
-
423
441
  # @param ext [Nokogiri::XML::Element]
424
442
  # @return [RelatonBib::StructuredIdentifierCollection]
425
- def fetch_structuredidentifier(ext)
443
+ def fetch_structuredidentifier(ext) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
426
444
  return unless ext
427
445
 
428
446
  sids = ext.xpath("structuredidentifier").map do |si|
@@ -437,12 +455,11 @@ module RelatonBib
437
455
  supplementtype: si.at("supplementtype")&.text,
438
456
  supplementnumber: si.at("supplementnumber")&.text,
439
457
  language: si.at("language")&.text,
440
- year: si.at("year")&.text,
458
+ year: si.at("year")&.text
441
459
  )
442
460
  end
443
461
  StructuredIdentifierCollection.new sids
444
462
  end
445
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
446
463
  end
447
464
  end
448
465
  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.2
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2020-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -248,7 +248,7 @@ homepage: https://github.com/relaton/relaton-bib
248
248
  licenses:
249
249
  - BSD-2-Clause
250
250
  metadata: {}
251
- post_install_message:
251
+ post_install_message:
252
252
  rdoc_options: []
253
253
  require_paths:
254
254
  - lib
@@ -264,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  requirements: []
266
266
  rubygems_version: 3.0.6
267
- signing_key:
267
+ signing_key:
268
268
  specification_version: 4
269
269
  summary: 'RelatonBib: Ruby XMLDOC impementation.'
270
270
  test_files: []