relaton-bib 1.4.0 → 2.1.7

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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration-tests.yml +54 -0
  3. data/.github/workflows/rake.yml +15 -0
  4. data/.github/workflows/release.yml +24 -0
  5. data/.gitignore +4 -1
  6. data/.rubocop.yml +3 -1
  7. data/CLAUDE.md +108 -0
  8. data/Gemfile +11 -0
  9. data/README.adoc +229 -314
  10. data/bin/console +1 -1
  11. data/docs/hash.adoc +132 -83
  12. data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
  13. data/lib/relaton/bib/converter/asciibib.rb +13 -0
  14. data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
  15. data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
  16. data/lib/relaton/bib/converter/bibtex.rb +23 -0
  17. data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +386 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +308 -0
  20. data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
  21. data/lib/relaton/bib/converter/bibxml.rb +51 -0
  22. data/lib/relaton/bib/hash_parser_v1.rb +767 -0
  23. data/lib/relaton/bib/item_data.rb +229 -0
  24. data/lib/relaton/bib/model/abstract.rb +16 -0
  25. data/lib/relaton/bib/model/address.rb +22 -0
  26. data/lib/relaton/bib/model/affiliation.rb +16 -0
  27. data/lib/relaton/bib/model/bibdata.rb +9 -0
  28. data/lib/relaton/bib/model/bibdata_shared.rb +10 -0
  29. data/lib/relaton/bib/model/bibitem.rb +9 -0
  30. data/lib/relaton/bib/model/bibitem_shared.rb +10 -0
  31. data/lib/relaton/bib/model/contact.rb +14 -0
  32. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  33. data/lib/relaton/bib/model/contributor.rb +29 -0
  34. data/lib/relaton/bib/model/copyright.rb +27 -0
  35. data/lib/relaton/bib/model/date.rb +29 -0
  36. data/lib/relaton/bib/model/depiction.rb +16 -0
  37. data/lib/relaton/bib/model/docidentifier.rb +34 -0
  38. data/lib/relaton/bib/model/doctype.rb +14 -0
  39. data/lib/relaton/bib/model/edition.rb +14 -0
  40. data/lib/relaton/bib/model/ext.rb +35 -0
  41. data/lib/relaton/bib/model/extent.rb +16 -0
  42. data/lib/relaton/bib/model/formattedref.rb +43 -0
  43. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  44. data/lib/relaton/bib/model/fullname.rb +11 -0
  45. data/lib/relaton/bib/model/ics.rb +49 -0
  46. data/lib/relaton/bib/model/image.rb +28 -0
  47. data/lib/relaton/bib/model/item.rb +44 -0
  48. data/lib/relaton/bib/model/item_base.rb +20 -0
  49. data/lib/relaton/bib/model/item_shared.rb +88 -0
  50. data/lib/relaton/bib/model/keyword.rb +30 -0
  51. data/lib/relaton/bib/model/locality.rb +18 -0
  52. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  53. data/lib/relaton/bib/model/localized_string.rb +48 -0
  54. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  55. data/lib/relaton/bib/model/logo.rb +14 -0
  56. data/lib/relaton/bib/model/medium.rb +22 -0
  57. data/lib/relaton/bib/model/note.rb +16 -0
  58. data/lib/relaton/bib/model/organization.rb +11 -0
  59. data/lib/relaton/bib/model/organization_type.rb +40 -0
  60. data/lib/relaton/bib/model/person.rb +36 -0
  61. data/lib/relaton/bib/model/phone.rb +14 -0
  62. data/lib/relaton/bib/model/place.rb +33 -0
  63. data/lib/relaton/bib/model/price.rb +14 -0
  64. data/lib/relaton/bib/model/relation.rb +41 -0
  65. data/lib/relaton/bib/model/series.rb +32 -0
  66. data/lib/relaton/bib/model/size.rb +23 -0
  67. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  68. data/lib/relaton/bib/model/status.rb +27 -0
  69. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  70. data/lib/relaton/bib/model/subdivision.rb +16 -0
  71. data/lib/relaton/bib/model/title.rb +56 -0
  72. data/lib/relaton/bib/model/type/plain_date.rb +16 -0
  73. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  74. data/lib/relaton/bib/model/uri.rb +18 -0
  75. data/lib/relaton/bib/model/validity.rb +16 -0
  76. data/lib/relaton/bib/model/version.rb +43 -0
  77. data/lib/relaton/bib/model_autoload.rb +85 -0
  78. data/lib/relaton/bib/namespace_helper.rb +21 -0
  79. data/lib/relaton/bib/sanitizer.rb +74 -0
  80. data/lib/relaton/bib/util.rb +18 -0
  81. data/lib/relaton/bib/version.rb +5 -0
  82. data/lib/relaton/bib/versions.json +35 -0
  83. data/lib/relaton/bib.rb +41 -0
  84. data/relaton-bib.gemspec +12 -16
  85. metadata +118 -129
  86. data/.github/workflows/macos.yml +0 -38
  87. data/.github/workflows/ubuntu.yml +0 -39
  88. data/.github/workflows/windows.yml +0 -41
  89. data/grammars/basicdoc.rng +0 -986
  90. data/grammars/biblio.rng +0 -1237
  91. data/grammars/isodoc.rng +0 -1613
  92. data/grammars/reqt.rng +0 -165
  93. data/lib/relaton_bib/bib_item_locality.rb +0 -107
  94. data/lib/relaton_bib/biblio_note.rb +0 -44
  95. data/lib/relaton_bib/biblio_version.rb +0 -49
  96. data/lib/relaton_bib/bibliographic_date.rb +0 -90
  97. data/lib/relaton_bib/bibliographic_item.rb +0 -726
  98. data/lib/relaton_bib/bibtex_parser.rb +0 -245
  99. data/lib/relaton_bib/classification.rb +0 -40
  100. data/lib/relaton_bib/contribution_info.rb +0 -109
  101. data/lib/relaton_bib/contributor.rb +0 -215
  102. data/lib/relaton_bib/copyright_association.rb +0 -77
  103. data/lib/relaton_bib/deep_dup.rb +0 -30
  104. data/lib/relaton_bib/document_identifier.rb +0 -95
  105. data/lib/relaton_bib/document_relation.rb +0 -94
  106. data/lib/relaton_bib/document_relation_collection.rb +0 -46
  107. data/lib/relaton_bib/document_status.rb +0 -93
  108. data/lib/relaton_bib/editorial_group.rb +0 -41
  109. data/lib/relaton_bib/formatted_ref.rb +0 -17
  110. data/lib/relaton_bib/formatted_string.rb +0 -55
  111. data/lib/relaton_bib/hash_converter.rb +0 -497
  112. data/lib/relaton_bib/hit.rb +0 -46
  113. data/lib/relaton_bib/hit_collection.rb +0 -73
  114. data/lib/relaton_bib/ics.rb +0 -37
  115. data/lib/relaton_bib/localized_string.rb +0 -93
  116. data/lib/relaton_bib/medium.rb +0 -44
  117. data/lib/relaton_bib/organization.rb +0 -135
  118. data/lib/relaton_bib/person.rb +0 -206
  119. data/lib/relaton_bib/place.rb +0 -49
  120. data/lib/relaton_bib/series.rb +0 -134
  121. data/lib/relaton_bib/structured_identifier.rb +0 -171
  122. data/lib/relaton_bib/technical_committee.rb +0 -36
  123. data/lib/relaton_bib/typed_title_string.rb +0 -96
  124. data/lib/relaton_bib/typed_uri.rb +0 -47
  125. data/lib/relaton_bib/validity.rb +0 -52
  126. data/lib/relaton_bib/version.rb +0 -3
  127. data/lib/relaton_bib/workers_pool.rb +0 -43
  128. data/lib/relaton_bib/workgroup.rb +0 -46
  129. data/lib/relaton_bib/xml_parser.rb +0 -463
  130. data/lib/relaton_bib.rb +0 -44
@@ -1,463 +0,0 @@
1
- require "nokogiri"
2
-
3
- module RelatonBib
4
- class XMLParser
5
- class << self
6
- def from_xml(xml)
7
- doc = Nokogiri::XML(xml)
8
- doc.remove_namespaces!
9
- bibitem = doc.at "/bibitem|/bibdata"
10
- if bibitem
11
- bib_item item_data(bibitem)
12
- else
13
- warn "[relaton-bib] WARNING: can't find bibitem or bibdata element "\
14
- "in the XML"
15
- end
16
- end
17
-
18
- private
19
-
20
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
21
-
22
- # @return [Hash]
23
- def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity
24
- ext = bibitem.at "//ext"
25
- {
26
- id: bibitem[:id]&.empty? ? nil : bibitem[:id],
27
- type: bibitem[:type]&.empty? ? nil : bibitem[:type],
28
- fetched: bibitem.at("./fetched")&.text,
29
- title: fetch_titles(bibitem),
30
- formattedref: fref(bibitem),
31
- link: fetch_link(bibitem),
32
- docid: fetch_docid(bibitem),
33
- docnumber: bibitem.at("./docnumber")&.text,
34
- date: fetch_dates(bibitem),
35
- contributor: fetch_contributors(bibitem),
36
- edition: bibitem.at("./edition")&.text,
37
- version: fetch_version(bibitem),
38
- biblionote: fetch_note(bibitem),
39
- language: fetch_language(bibitem),
40
- script: fetch_script(bibitem),
41
- abstract: fetch_abstract(bibitem),
42
- docstatus: fetch_status(bibitem),
43
- copyright: fetch_copyright(bibitem),
44
- relation: fetch_relations(bibitem),
45
- series: fetch_series(bibitem),
46
- medium: fetch_medium(bibitem),
47
- place: fetch_place(bibitem),
48
- extent: fetch_extent(bibitem),
49
- accesslocation: bibitem.xpath("./accesslocation").map(&:text),
50
- classification: fetch_classification(bibitem),
51
- keyword: bibitem.xpath("keyword").map(&:text),
52
- license: bibitem.xpath("license").map(&:text),
53
- validity: fetch_validity(bibitem),
54
- doctype: ext&.at("doctype")&.text,
55
- editorialgroup: fetch_editorialgroup(ext),
56
- ics: fetch_ics(ext),
57
- structuredidentifier: fetch_structuredidentifier(ext),
58
- }
59
- end
60
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
61
-
62
- def fetch_version(item)
63
- version = item.at "./version"
64
- return unless version
65
-
66
- revision_date = version.at("revision-date")&.text
67
- draft = version.xpath("draft").map &:text
68
- RelatonBib::BibliographicItem::Version.new revision_date, draft
69
- end
70
-
71
- def fetch_place(item)
72
- item.xpath("./place").map do |pl|
73
- Place.new(name: pl.text, uri: pl[:uri], region: pl[:region])
74
- end
75
- end
76
-
77
- def fetch_note(item)
78
- item.xpath("./note").map do |n|
79
- BiblioNote.new(
80
- content: n.text,
81
- type: n[:type],
82
- format: n[:format],
83
- language: n[:language],
84
- script: n[:script]
85
- )
86
- end
87
- end
88
-
89
- def fetch_language(item)
90
- item.xpath("./language").reduce([]) do |a, l|
91
- l.text.empty? ? a : a << l.text
92
- end
93
- end
94
-
95
- def fetch_script(item)
96
- item.xpath("./script").reduce([]) do |a, s|
97
- s.text.empty? ? a : a << s.text
98
- end
99
- end
100
-
101
- def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
102
- item.xpath("./series").reduce([]) do |mem, sr|
103
- abbr = sr.at "abbreviation"
104
- abbreviation = abbr &&
105
- LocalizedString.new(abbr.text, abbr[:language], abbr[:script])
106
- formattedref = fref(sr)
107
- title = ttitle(sr.at("title"))
108
- next mem unless formattedref || title
109
-
110
- mem << Series.new(
111
- type: sr[:type], formattedref: formattedref,
112
- title: title, place: sr.at("place")&.text,
113
- organization: sr.at("organization")&.text,
114
- abbreviation: abbreviation, from: sr.at("from")&.text,
115
- to: sr.at("to")&.text, number: sr.at("number")&.text,
116
- partnumber: sr.at("partnumber")&.text
117
- )
118
- end
119
- end
120
-
121
- def fetch_medium(item)
122
- medium = item.at("./medium")
123
- return unless medium
124
-
125
- Medium.new(
126
- form: medium.at("form")&.text, size: medium.at("size")&.text,
127
- scale: medium.at("scale")&.text
128
- )
129
- end
130
-
131
- def fetch_extent(item)
132
- item.xpath("./extent").map do |ex|
133
- BibItemLocality.new(
134
- ex[:type], ex.at("referenceFrom")&.text, ex.at("referenceTo")&.text
135
- )
136
- end
137
- end
138
-
139
- def fetch_classification(item)
140
- item.xpath("classification").map do |cls|
141
- Classification.new type: cls[:type], value: cls.text
142
- end
143
- end
144
-
145
- def fetch_validity(item)
146
- vl = item.at("./validity")
147
- return unless vl
148
-
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")
155
- Validity.new begins: begins, ends: ends, revision: revision
156
- end
157
-
158
- # @param item [Nokogiri::XML::Element]
159
- # @return [Array<RelatonBib::DocumentIdentifier>]
160
- def fetch_docid(item)
161
- item.xpath("./docidentifier").map do |did|
162
- DocumentIdentifier.new(id: did.text, type: did[:type],
163
- scope: did[:scope])
164
- end
165
- end
166
-
167
- def fetch_titles(item)
168
- item.xpath("./title").map { |t| ttitle t }
169
- end
170
-
171
- def ttitle(title)
172
- return unless title
173
-
174
- variants = title.xpath("variant").map do |v|
175
- LocalizedString.new v.text, v[:language], v[:script]
176
- end
177
- content = variants.any? ? variants : title.text
178
- TypedTitleString.new(
179
- type: title[:type], content: content, language: title[:language],
180
- script: title[:script], format: title[:format]
181
- )
182
- end
183
-
184
- def fetch_status(item)
185
- status = item.at("./status")
186
- return unless status
187
-
188
- stg = status.at "stage"
189
- DocumentStatus.new(
190
- stage: stg ? stage(stg) : status.text,
191
- substage: stage(status.at("substage")),
192
- iteration: status.at("iteration")&.text
193
- )
194
- end
195
-
196
- # @param node [Nokogiri::XML::Elemen]
197
- # @return [RelatonBib::DocumentStatus::Stage]
198
- def stage(elm)
199
- return unless elm
200
-
201
- DocumentStatus::Stage.new(value: elm.text,
202
- abbreviation: elm[:abbreviation])
203
- end
204
-
205
- def fetch_dates(item) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
206
- item.xpath("./date").reduce([]) do |a, d|
207
- type = d[:type].to_s.empty? ? "published" : d[:type]
208
- if (on = d.at("on"))
209
- a << RelatonBib::BibliographicDate.new(type: type, on: on.text,
210
- to: d.at("to")&.text)
211
- elsif (from = d.at("from"))
212
- a << RelatonBib::BibliographicDate.new(type: type, from: from.text,
213
- to: d.at("to")&.text)
214
- end
215
- end
216
- end
217
-
218
- def get_org(org) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
219
- names = org.xpath("name").map do |n|
220
- { content: n.text, language: n[:language], script: n[:script] }
221
- end
222
- identifier = org.xpath("./identifier").map do |i|
223
- OrgIdentifier.new(i[:type], i.text)
224
- end
225
- Organization.new(name: names,
226
- abbreviation: org.at("abbreviation")&.text,
227
- subdivision: org.at("subdivision")&.text,
228
- url: org.at("uri")&.text,
229
- identifier: identifier)
230
- end
231
-
232
- def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
233
- affiliations = person.xpath("./affiliation").map do |a|
234
- org = a.at "./organization"
235
- desc = a.xpath("./description").map do |e|
236
- FormattedString.new(content: e.text, language: e[:language],
237
- script: e[:script], format: e[:format])
238
- end
239
- Affiliation.new organization: get_org(org), description: desc
240
- end
241
-
242
- contact = person.xpath("./address|./phone|./email|./uri").map do |c|
243
- if c.name == "address"
244
- streets = c.xpath("./street").map(&:text)
245
- Address.new(
246
- street: streets,
247
- city: c.at("./city")&.text,
248
- state: c.at("./state")&.text,
249
- country: c.at("./country")&.text,
250
- postcode: c.at("./postcode")&.text
251
- )
252
- else
253
- Contact.new(type: c.name, value: c.text)
254
- end
255
- end
256
-
257
- identifier = person.xpath("./identifier").map do |pi|
258
- PersonIdentifier.new pi[:type], pi.text
259
- end
260
-
261
- cn = person.at "./name/completename"
262
- cname = cn && LocalizedString.new(cn.text, cn[:language], cn[:script])
263
- sn = person.at "./name/surname"
264
- sname = sn && LocalizedString.new(sn.text, sn[:language], sn[:script])
265
-
266
- name = FullName.new(
267
- completename: cname, surname: sname,
268
- initial: name_part(person, "initial"),
269
- forename: name_part(person, "forename"),
270
- addition: name_part(person, "addition"),
271
- prefix: name_part(person, "prefix")
272
- )
273
-
274
- Person.new(
275
- name: name,
276
- affiliation: affiliations,
277
- contact: contact,
278
- identifier: identifier
279
- )
280
- end
281
-
282
- def name_part(person, part)
283
- person.xpath("./name/#{part}").map do |np|
284
- LocalizedString.new np.text, np[:language]
285
- end
286
- end
287
-
288
- # @param item [Nokogiri::XML::Element]
289
- # @return [Array<RelatonBib::ContributionInfo>]
290
- def fetch_contributors(item)
291
- item.xpath("./contributor").map do |c|
292
- entity = if (org = c.at "./organization") then get_org(org)
293
- elsif (person = c.at "./person") then get_person(person)
294
- end
295
- role = c.xpath("./role").map do |r|
296
- { type: r[:type],
297
- description: r.xpath("./description").map(&:text) }
298
- end
299
- ContributionInfo.new entity: entity, role: role
300
- end
301
- end
302
-
303
- # @param item [Nokogiri::XML::Element]
304
- # @return [Array<RelatonBib::FormattedString>]
305
- def fetch_abstract(item)
306
- item.xpath("./abstract").map do |a|
307
- FormattedString.new(content: a.text, language: a[:language],
308
- script: a[:script], format: a[:format])
309
- end
310
- end
311
-
312
- # @param item [Nokogiri::XML::Element]
313
- # @return [Array<RelatonBib::CopyrightAssociation>]
314
- def fetch_copyright(item)
315
- item.xpath("./copyright").map do |cp|
316
- owner = cp.xpath("owner").map do |o|
317
- ContributionInfo.new entity: get_org(o.at("organization"))
318
- end
319
- from = cp.at("from")&.text
320
- to = cp.at("to")&.text
321
- scope = cp.at("scope")&.text
322
- CopyrightAssociation.new(owner: owner, from: from, to: to,
323
- scope: scope)
324
- end
325
- end
326
-
327
- # @param item [Nokogiri::XML::Element]
328
- # @return [Arra<RelatonBib::TypedUri>]
329
- def fetch_link(item)
330
- item.xpath("./uri").map do |l|
331
- TypedUri.new type: l[:type], content: l.text
332
- end
333
- end
334
-
335
- # @param item [Nokogiri::XML::Element]
336
- # @param klass [RelatonBib::DocumentRelation.class,
337
- # RelatonNist::DocumentRelation.class]
338
- # @return [Array<RelatonBib::DocumentRelation>]
339
- def fetch_relations(item, klass = DocumentRelation)
340
- item.xpath("./relation").map do |rel|
341
- klass.new(
342
- type: rel[:type]&.empty? ? nil : rel[:type],
343
- description: relation_description(rel),
344
- bibitem: bib_item(item_data(rel.at("./bibitem"))),
345
- locality: localities(rel),
346
- source_locality: source_localities(rel)
347
- )
348
- end
349
- end
350
-
351
- # @param rel [Nokogiri::XML::Element]
352
- # @return [RelatonBib::FormattedString, NilClass]
353
- def relation_description(rel)
354
- d = rel.at "./description"
355
- return unless d
356
-
357
- FormattedString.new(content: d.text, language: d[:language],
358
- script: d[:script], format: d[:format])
359
- end
360
-
361
- # @param item_hash [Hash]
362
- # @return [RelatonBib::BibliographicItem]
363
- def bib_item(item_hash)
364
- BibliographicItem.new item_hash
365
- end
366
-
367
- # @param rel [Nokogiri::XML::Element]
368
- # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
369
- def localities(rel)
370
- rel.xpath("./locality|./localityStack").map do |lc|
371
- if lc[:type]
372
- LocalityStack.new [locality(lc)]
373
- else
374
- LocalityStack.new(lc.xpath("./locality").map { |l| locality l })
375
- end
376
- end
377
- end
378
-
379
- # @param loc [Nokogiri::XML::Element]
380
- # @return [RelatonBib::Locality]
381
- def locality(loc, klass = Locality)
382
- ref_to = (rt = loc.at("./referenceTo")) && LocalizedString.new(rt.text)
383
- klass.new(
384
- loc[:type],
385
- LocalizedString.new(loc.at("./referenceFrom").text),
386
- ref_to
387
- )
388
- end
389
-
390
- # @param rel [Nokogiri::XML::Element]
391
- # @return [Array<RelatonBib::SourceLocality,
392
- # RelatonBib::SourceLocalityStack>]
393
- def source_localities(rel)
394
- rel.xpath("./sourceLocality|./sourceLocalityStack").map do |lc|
395
- if lc[:type]
396
- SourceLocalityStack.new [locality(lc, SourceLocality)]
397
- else
398
- sls = lc.xpath("./sourceLocality").map do |l|
399
- locality l, SourceLocality
400
- end
401
- SourceLocalityStack.new sls
402
- end
403
- end
404
- end
405
-
406
- # @param item [Nokogiri::XML::Element]
407
- # @return [RelatonBib::FormattedRef, NilClass]
408
- def fref(item)
409
- ident = item&.at("./formattedref")
410
- return unless ident
411
-
412
- FormattedRef.new(
413
- content: ident&.text, format: ident[:format],
414
- language: ident[:language], script: ident[:script]
415
- )
416
- end
417
-
418
- # @param ext [Nokogiri::XML::Element]
419
- # @return [RelatonBib::EditorialGroup, nil]
420
- def fetch_editorialgroup(ext)
421
- return unless ext && (eg = ext.at "editorialgroup")
422
-
423
- eg = eg.xpath("technical-committee").map do |tc|
424
- wg = WorkGroup.new(content: tc.text, number: tc[:number]&.to_i,
425
- type: tc[:type])
426
- TechnicalCommittee.new wg
427
- end
428
- EditorialGroup.new eg if eg.any?
429
- end
430
-
431
- def fetch_ics(ext)
432
- return [] unless ext
433
-
434
- ext.xpath("ics").map do |ics|
435
- ICS.new code: ics.at("code")&.text, text: ics.at("text")&.text
436
- end
437
- end
438
-
439
- # @param ext [Nokogiri::XML::Element]
440
- # @return [RelatonBib::StructuredIdentifierCollection]
441
- def fetch_structuredidentifier(ext) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
442
- return unless ext
443
-
444
- sids = ext.xpath("structuredidentifier").map do |si|
445
- StructuredIdentifier.new(
446
- type: si[:type],
447
- agency: si.xpath("agency").map(&:text),
448
- class: si.at("class")&.text,
449
- docnumber: si.at("docnumber")&.text,
450
- partnumber: si.at("partnumber")&.text,
451
- edition: si.at("edition")&.text,
452
- version: si.at("version")&.text,
453
- supplementtype: si.at("supplementtype")&.text,
454
- supplementnumber: si.at("supplementnumber")&.text,
455
- language: si.at("language")&.text,
456
- year: si.at("year")&.text
457
- )
458
- end
459
- StructuredIdentifierCollection.new sids
460
- end
461
- end
462
- end
463
- end
data/lib/relaton_bib.rb DELETED
@@ -1,44 +0,0 @@
1
- require "relaton_bib/version"
2
- require "relaton_bib/deep_dup"
3
- require "relaton_bib/bibliographic_item"
4
- require "relaton_bib/hit_collection"
5
- require "relaton_bib/hit"
6
-
7
- module RelatonBib
8
- class Error < StandardError; end
9
-
10
- class RequestError < StandardError; end
11
-
12
- class << self
13
- # @param date [String, Integer, Date]
14
- # @return [Date, NilClass]
15
- def parse_date(date) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
16
- return date if date.is_a?(Date)
17
-
18
- sdate = date.to_s
19
- case sdate
20
- when /(?<date>\w+\s\d{4})/ # February 2012
21
- Date.strptime($~[:date], "%B %Y")
22
- when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
23
- Date.strptime($~[:date], "%B %d, %Y")
24
- when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
25
- Date.parse($~[:date])
26
- when /(?<date>\d{4}-\d{2})/ # 2012-02
27
- Date.strptime date, "%Y-%m"
28
- when /(?<date>\d{4})/ then Date.strptime $~[:date], "%Y" # 2012
29
- end
30
- end
31
- end
32
-
33
- private
34
-
35
- # @param array [Array]
36
- # @return [Array<String>, String]
37
- def single_element_array(array) # rubocop:disable Metrics/CyclomaticComplexity
38
- if array.size > 1
39
- array.map { |e| e.is_a?(String) ? e : e.to_hash }
40
- else
41
- array.first&.is_a?(String) ? array[0] : array.first&.to_hash
42
- end
43
- end
44
- end