relaton-bib 1.20.8 → 2.0.0

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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +1 -1
  4. data/CLAUDE.md +96 -0
  5. data/Gemfile +1 -4
  6. data/README.adoc +195 -154
  7. data/bin/console +1 -1
  8. data/grammars/basicdoc.rng +1572 -671
  9. data/grammars/biblio-standoc.rng +107 -46
  10. data/grammars/biblio.rng +1012 -377
  11. data/grammars/versions.json +26 -26
  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 +383 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +305 -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 +754 -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 +24 -0
  28. data/lib/relaton/bib/model/bibitem.rb +23 -0
  29. data/lib/relaton/bib/model/contact.rb +18 -0
  30. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  31. data/lib/relaton/bib/model/contributor.rb +71 -0
  32. data/lib/relaton/bib/model/copyright.rb +27 -0
  33. data/lib/relaton/bib/model/date.rb +31 -0
  34. data/lib/relaton/bib/model/depiction.rb +16 -0
  35. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  36. data/lib/relaton/bib/model/doctype.rb +14 -0
  37. data/lib/relaton/bib/model/edition.rb +14 -0
  38. data/lib/relaton/bib/model/ext.rb +26 -0
  39. data/lib/relaton/bib/model/extent.rb +16 -0
  40. data/lib/relaton/bib/model/formattedref.rb +43 -0
  41. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  42. data/lib/relaton/bib/model/fullname.rb +11 -0
  43. data/lib/relaton/bib/model/ics.rb +23 -0
  44. data/lib/relaton/bib/model/image.rb +28 -0
  45. data/lib/relaton/bib/model/item.rb +137 -0
  46. data/lib/relaton/bib/model/item_base.rb +27 -0
  47. data/lib/relaton/bib/model/keyword.rb +30 -0
  48. data/lib/relaton/bib/model/locality.rb +18 -0
  49. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  50. data/lib/relaton/bib/model/localized_string.rb +57 -0
  51. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  52. data/lib/relaton/bib/model/logo.rb +14 -0
  53. data/lib/relaton/bib/model/medium.rb +22 -0
  54. data/lib/relaton/bib/model/note.rb +16 -0
  55. data/lib/relaton/bib/model/organization.rb +13 -0
  56. data/lib/relaton/bib/model/organization_type.rb +42 -0
  57. data/lib/relaton/bib/model/person.rb +36 -0
  58. data/lib/relaton/bib/model/phone.rb +14 -0
  59. data/lib/relaton/bib/model/place.rb +33 -0
  60. data/lib/relaton/bib/model/price.rb +14 -0
  61. data/lib/relaton/bib/model/relation.rb +43 -0
  62. data/lib/relaton/bib/model/series.rb +34 -0
  63. data/lib/relaton/bib/model/size.rb +23 -0
  64. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  65. data/lib/relaton/bib/model/status.rb +27 -0
  66. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  67. data/lib/relaton/bib/model/subdivision.rb +16 -0
  68. data/lib/relaton/bib/model/title.rb +56 -0
  69. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  70. data/lib/relaton/bib/model/uri.rb +18 -0
  71. data/lib/relaton/bib/model/validity.rb +16 -0
  72. data/lib/relaton/bib/model/version.rb +14 -0
  73. data/lib/relaton/bib/namespace_helper.rb +21 -0
  74. data/lib/relaton/bib/util.rb +18 -0
  75. data/lib/relaton/bib/version.rb +5 -0
  76. data/lib/relaton/bib.rb +45 -0
  77. data/relaton-bib.gemspec +11 -8
  78. metadata +125 -67
  79. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  80. data/lib/relaton_bib/biblio_note.rb +0 -72
  81. data/lib/relaton_bib/biblio_version.rb +0 -46
  82. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  83. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  84. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  85. data/lib/relaton_bib/bibtex_parser.rb +0 -246
  86. data/lib/relaton_bib/bibxml_parser.rb +0 -422
  87. data/lib/relaton_bib/classification.rb +0 -40
  88. data/lib/relaton_bib/config.rb +0 -16
  89. data/lib/relaton_bib/contribution_info.rb +0 -117
  90. data/lib/relaton_bib/contributor.rb +0 -277
  91. data/lib/relaton_bib/copyright_association.rb +0 -79
  92. data/lib/relaton_bib/deep_dup.rb +0 -30
  93. data/lib/relaton_bib/document_identifier.rb +0 -118
  94. data/lib/relaton_bib/document_relation.rb +0 -95
  95. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  96. data/lib/relaton_bib/document_status.rb +0 -92
  97. data/lib/relaton_bib/document_type.rb +0 -52
  98. data/lib/relaton_bib/edition.rb +0 -55
  99. data/lib/relaton_bib/editorial_group.rb +0 -41
  100. data/lib/relaton_bib/extent.rb +0 -39
  101. data/lib/relaton_bib/forename.rb +0 -65
  102. data/lib/relaton_bib/formatted_ref.rb +0 -17
  103. data/lib/relaton_bib/formatted_string.rb +0 -133
  104. data/lib/relaton_bib/full_name.rb +0 -108
  105. data/lib/relaton_bib/hash_converter.rb +0 -568
  106. data/lib/relaton_bib/hit.rb +0 -52
  107. data/lib/relaton_bib/hit_collection.rb +0 -105
  108. data/lib/relaton_bib/ics.rb +0 -42
  109. data/lib/relaton_bib/image.rb +0 -95
  110. data/lib/relaton_bib/localized_string.rb +0 -149
  111. data/lib/relaton_bib/medium.rb +0 -76
  112. data/lib/relaton_bib/organization.rb +0 -165
  113. data/lib/relaton_bib/person.rb +0 -129
  114. data/lib/relaton_bib/place.rb +0 -203
  115. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  116. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  117. data/lib/relaton_bib/series.rb +0 -119
  118. data/lib/relaton_bib/structured_identifier.rb +0 -173
  119. data/lib/relaton_bib/technical_committee.rb +0 -34
  120. data/lib/relaton_bib/typed_title_string.rb +0 -191
  121. data/lib/relaton_bib/typed_uri.rb +0 -57
  122. data/lib/relaton_bib/util.rb +0 -16
  123. data/lib/relaton_bib/validity.rb +0 -52
  124. data/lib/relaton_bib/version.rb +0 -3
  125. data/lib/relaton_bib/workers_pool.rb +0 -43
  126. data/lib/relaton_bib/workgroup.rb +0 -58
  127. data/lib/relaton_bib/xml_parser.rb +0 -718
  128. data/lib/relaton_bib.rb +0 -111
@@ -1,568 +0,0 @@
1
- module RelatonBib
2
- module HashConverter
3
- extend self
4
- # @param args [Hash]
5
- # @return [Hash]
6
- def hash_to_bib(args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
7
- return nil unless args.is_a?(Hash)
8
-
9
- ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
10
- title_hash_to_bib(ret)
11
- link_hash_to_bib(ret)
12
- language_hash_to_bib(ret)
13
- script_hash_to_bib(ret)
14
- dates_hash_to_bib(ret)
15
- docid_hash_to_bib(ret)
16
- version_hash_to_bib(ret)
17
- biblionote_hash_to_bib(ret)
18
- abstract_hash_to_bib(ret)
19
- formattedref_hash_to_bib(ret)
20
- docstatus_hash_to_bib(ret)
21
- contributors_hash_to_bib(ret)
22
- copyright_hash_to_bib(ret)
23
- relations_hash_to_bib(ret)
24
- series_hash_to_bib(ret)
25
- medium_hash_to_bib(ret)
26
- place_hash_to_bib(ret)
27
- extent_hash_to_bib(ret)
28
- size_hash_to_bib(ret)
29
- accesslocation_hash_to_bib(ret)
30
- classification_hash_to_bib(ret)
31
- validity_hash_to_bib(ret)
32
- keyword_hash_to_bib(ret)
33
- # ret[:keyword] = RelatonBib.array(ret[:keyword])
34
- ret[:license] = RelatonBib.array(ret[:license])
35
- # editorialgroup_hash_to_bib ret
36
- # ics_hash_to_bib ret
37
- # structuredidentifier_hash_to_bib ret
38
- # doctype_hash_to_bib ret
39
- ext_has_to_bib ret
40
- ret
41
- end
42
-
43
- def ext_has_to_bib(ret)
44
- doctype_hash_to_bib ret
45
- ret[:subdoctype] = ret[:ext][:subdoctype] if ret.dig(:ext, :subdoctype)
46
- editorialgroup_hash_to_bib ret
47
- ics_hash_to_bib ret
48
- structuredidentifier_hash_to_bib ret
49
- end
50
-
51
- def keyword_hash_to_bib(ret)
52
- ret[:keyword] = RelatonBib.array(ret[:keyword]).map do |keyword|
53
- localizedstring keyword
54
- end
55
- end
56
-
57
- def extent_hash_to_bib(ret)
58
- return unless ret[:extent]
59
-
60
- ret[:extent] = RelatonBib.array(ret[:extent]).map do |e|
61
- RelatonBib::Extent.new locality(e)
62
- end
63
- end
64
-
65
- def locality(loc)
66
- if loc[:locality_stack]
67
- RelatonBib.array(loc[:locality_stack]).map do |l|
68
- LocalityStack.new locality(l)
69
- end
70
- else
71
- RelatonBib.array(loc[:locality]).map do |l|
72
- Locality.new(l[:type], l[:reference_from], l[:reference_to])
73
- end
74
- end
75
- end
76
-
77
- def size_hash_to_bib(ret)
78
- return unless ret[:size]
79
-
80
- ret[:size] = RelatonBib.array(ret[:size])
81
- size = ret[:size]&.map do |val|
82
- BibliographicSize::Value.new(**val)
83
- end
84
- ret[:size] = BibliographicSize.new(size)
85
- end
86
-
87
- def title_hash_to_bib(ret)
88
- return unless ret[:title]
89
-
90
- ret[:title] = RelatonBib.array(ret[:title])
91
- .reduce(TypedTitleStringCollection.new) do |m, t|
92
- if t.is_a?(Hash) then m << TypedTitleString.new(**t)
93
- else
94
- m + TypedTitleString.from_string(t)
95
- end
96
- end
97
- end
98
-
99
- def language_hash_to_bib(ret)
100
- return unless ret[:language]
101
-
102
- ret[:language] = RelatonBib.array(ret[:language])
103
- end
104
-
105
- def script_hash_to_bib(ret)
106
- return unless ret[:script]
107
-
108
- ret[:script] = RelatonBib.array(ret[:script])
109
- end
110
-
111
- def abstract_hash_to_bib(ret)
112
- return unless ret[:abstract]
113
-
114
- ret[:abstract] = RelatonBib.array(ret[:abstract]).map do |a|
115
- a.is_a?(String) ? FormattedString.new(content: a) : a
116
- end
117
- end
118
-
119
- def link_hash_to_bib(ret)
120
- return unless ret[:link]
121
-
122
- ret[:link] = RelatonBib.array(ret[:link])
123
- end
124
-
125
- def place_hash_to_bib(ret)
126
- return unless ret[:place]
127
-
128
- ret[:place] = RelatonBib.array(ret[:place]).map do |pl|
129
- pl.is_a?(String) ? Place.new(name: pl) : Place.new(**pl)
130
- end
131
- end
132
-
133
- def accesslocation_hash_to_bib(ret)
134
- return unless ret[:accesslocation]
135
-
136
- ret[:accesslocation] = RelatonBib.array(ret[:accesslocation])
137
- end
138
-
139
- def dates_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
140
- return unless ret[:date]
141
-
142
- ret[:date] = RelatonBib.array(ret[:date])
143
- ret[:date].each_with_index do |d, i|
144
- # value is synonym of on: it is reserved word in YAML
145
- if d[:value]
146
- ret[:date][i][:on] ||= d[:value]
147
- ret[:date][i].delete(:value)
148
- end
149
- end
150
- end
151
-
152
- def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
153
- return unless ret[:docid]
154
-
155
- ret[:docid] = RelatonBib.array(ret[:docid]).map do |id|
156
- id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
157
- create_docid(**id)
158
- end
159
- end
160
-
161
- def create_docid(**args)
162
- DocumentIdentifier.new(**args)
163
- end
164
-
165
- def version_hash_to_bib(ret)
166
- return unless ret[:version]
167
-
168
- ret[:version] = RelatonBib.array(ret[:version]).map do |v|
169
- BibliographicItem::Version.new(v[:revision_date], v[:draft])
170
- end
171
- end
172
-
173
- def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
174
- return unless ret[:biblionote]
175
-
176
- ret[:biblionote] = RelatonBib.array(ret[:biblionote])
177
- .reduce(BiblioNoteCollection.new([])) do |mem, n|
178
- mem << if n.is_a?(String) then BiblioNote.new content: n
179
- else BiblioNote.new(**n)
180
- end
181
- end
182
- end
183
-
184
- def formattedref_hash_to_bib(ret)
185
- ret[:formattedref] &&
186
- ret[:formattedref] = formattedref(ret[:formattedref])
187
- end
188
-
189
- def docstatus_hash_to_bib(ret)
190
- ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
191
- stage: stage(ret[:docstatus][:stage]),
192
- substage: stage(ret[:docstatus][:substage]),
193
- iteration: ret[:docstatus][:iteration],
194
- )
195
- end
196
-
197
- # @param stg [Hash]
198
- # @return [RelatonBib::DocumentStatus::Stage]
199
- def stage(stg)
200
- return unless stg
201
-
202
- args = stg.is_a?(String) ? { value: stg } : stg
203
- DocumentStatus::Stage.new(**args)
204
- end
205
-
206
- def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
207
- return unless ret[:contributor]
208
-
209
- ret[:contributor] = RelatonBib.array(ret[:contributor])
210
- ret[:contributor]&.each_with_index do |c, i|
211
- roles = RelatonBib.array(ret[:contributor][i][:role]).map do |r|
212
- if r.is_a? Hash
213
- desc = RelatonBib.array(r[:description]).map { |d| d.is_a?(String) ? d : d[:content] }
214
- { type: r[:type], description: desc }
215
- # elsif r.is_a? Array
216
- # { type: r[0], description: r.fetch(1) }
217
- else
218
- { type: r }
219
- end
220
- end
221
- ret[:contributor][i][:role] = roles
222
- ret[:contributor][i][:entity] = if c[:person]
223
- person_hash_to_bib(c[:person])
224
- else
225
- org_hash_to_bib(c[:organization])
226
- end
227
- ret[:contributor][i].delete(:person)
228
- ret[:contributor][i].delete(:organization)
229
- end
230
- end
231
-
232
- def org_hash_to_bib(org) # rubocop:disable Metrics/AbcSize
233
- return nil if org.nil?
234
-
235
- org[:identifier] = RelatonBib.array(org[:identifier])&.map do |a|
236
- OrgIdentifier.new(a[:type], a[:id])
237
- end
238
- org[:subdivision] = RelatonBib.array(org[:subdivision]).map do |sd|
239
- LocalizedString.new sd.is_a?(Hash) ? sd[:content] : sd
240
- end
241
- org[:contact] = contacts_hash_to_bib(org)
242
- org[:logo] = Image.new(**org[:logo][:image]) if org[:logo]
243
- org
244
- end
245
-
246
- def person_hash_to_bib(person)
247
- Person.new(
248
- name: fullname_hash_to_bib(person),
249
- credential: RelatonBib.array(person[:credential]),
250
- affiliation: affiliation_hash_to_bib(person),
251
- contact: contacts_hash_to_bib(person),
252
- identifier: person_identifiers_hash_to_bib(person),
253
- )
254
- end
255
-
256
- def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize
257
- n = person[:name]
258
- fname, inits = given_hash_to_bib n[:given] || n # `n` is for backward compatibility
259
- FullName.new(
260
- abbreviation: localizedstring(n[:abbreviation]),
261
- forename: fname, initials: inits,
262
- addition: RelatonBib.array(n[:addition])&.map { |f| localizedstring(f) },
263
- prefix: RelatonBib.array(n[:prefix])&.map { |f| localizedstring(f) },
264
- surname: localizedstring(n[:surname]),
265
- completename: localizedstring(n[:completename])
266
- )
267
- end
268
-
269
- def given_hash_to_bib(given)
270
- return [[], nil] unless given
271
-
272
- fname = RelatonBib.array(given[:forename])&.map { |f| forename_hash_to_bib(f) }
273
- inits = localizedstring(given[:formatted_initials])
274
- [fname, inits]
275
- end
276
-
277
- def forename_hash_to_bib(fname)
278
- case fname
279
- when Hash then Forename.new(**fname)
280
- when String then Forename.new(content: fname)
281
- end
282
- end
283
-
284
- def person_identifiers_hash_to_bib(person)
285
- RelatonBib.array(person[:identifier])&.map do |a|
286
- PersonIdentifier.new(a[:type], a[:id])
287
- end
288
- end
289
-
290
- def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
291
- return [] unless person[:affiliation]
292
-
293
- RelatonBib.array(person[:affiliation]).map do |a|
294
- a[:description] = RelatonBib.array(a[:description]).map do |d|
295
- cnt = if d.is_a?(Hash)
296
- { content: d[:content], language: d[:language],
297
- script: d[:script], format: d[:format] }
298
- else { content: d }
299
- end
300
- FormattedString.new(**cnt)
301
- end
302
- Affiliation.new(
303
- organization: Organization.new(**org_hash_to_bib(a[:organization])),
304
- description: a[:description], name: localizedstring(a[:name])
305
- )
306
- end
307
- end
308
-
309
- def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
310
- return [] unless entity[:contact]
311
-
312
- RelatonBib.array(entity[:contact]).map do |a|
313
- type, value = a.reject { |k, _| k == :type }.flatten
314
- case type
315
- when :street, :city, :state, :country, :postcode # it's for old version compatibility, should be removed in the future
316
- a[:street] = RelatonBib.array(a[:street])
317
- Address.new(**a)
318
- when :address then create_address(a[:address])
319
- when :phone, :email, :uri
320
- Contact.new(type: type.to_s, value: value, subtype: a[:type])
321
- else # it's for old version compatibility, should be removed in the future
322
- Contact.new(**a)
323
- end
324
- end
325
- end
326
-
327
- def create_address(adr)
328
- if adr.is_a?(Hash)
329
- adr[:street] = RelatonBib.array(adr[:street])
330
- Address.new(**adr)
331
- else
332
- Address.new(formatted_address: adr)
333
- end
334
- end
335
-
336
- # @param ret [Hash]
337
- def copyright_hash_to_bib(ret)
338
- return unless ret[:copyright]
339
-
340
- ret[:copyright] = RelatonBib.array(ret[:copyright]).map do |c|
341
- c[:owner] = RelatonBib.array(c[:owner]).map do |o|
342
- org_hash_to_bib(o)
343
- end
344
- c
345
- end
346
- end
347
-
348
- # @param ret [Hash]
349
- def relations_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
350
- return unless ret[:relation]
351
-
352
- ret[:relation] = RelatonBib.array(ret[:relation])
353
- ret[:relation]&.each do |rel|
354
- rel[:description] = FormattedString.new(**rel[:description]) if rel[:description]
355
- relation_bibitem_hash_to_bib(rel)
356
- relation_locality_hash_to_bib(rel)
357
- relation_locality_stack_hash_to_bib(rel)
358
- relation_source_locality_hash_to_bib(rel)
359
- relaton_source_locality_stack_hash_to_bib(rel)
360
- end
361
- end
362
-
363
- # @param rel [Hash] relation
364
- def relation_bibitem_hash_to_bib(rel)
365
- if rel[:bibitem]
366
- rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem])
367
- else
368
- Util.warn "Bibitem missing: `#{rel}`"
369
- rel[:bibitem] = nil
370
- end
371
- end
372
-
373
- # @param item_hash [Hash]
374
- # @return [RelatonBib::BibliographicItem]
375
- def bib_item(item_hash)
376
- BibliographicItem.new(**item_hash)
377
- end
378
-
379
- # @param rel [Hash] relation
380
- # @return [RelatonBib::LocalityStack]
381
- def relation_locality_hash_to_bib(rel)
382
- return unless rel[:locality]&.any?
383
-
384
- rel[:locality] = RelatonBib.array(rel[:locality]).map do |bl|
385
- Locality.new(bl[:type], bl[:reference_from], bl[:reference_to])
386
- end
387
- end
388
-
389
- def relation_locality_stack_hash_to_bib(rel)
390
- return unless rel[:locality_stack]&.any?
391
-
392
- rel[:locality_stack] = RelatonBib.array(rel[:locality_stack]).map do |ls|
393
- LocalityStack.new relation_locality_hash_to_bib(ls)
394
- end
395
- end
396
-
397
- # def locality_locality_stack(lls)
398
- # if lls[:locality_stack]
399
- # RelatonBib.array(lls[:locality_stack]).map do |lc|
400
- # l = lc[:locality] || lc
401
- # Locality.new(l[:type], l[:reference_from], l[:reference_to])
402
- # end
403
- # else
404
- # [Locality.new(lls[:type], lls[:reference_from], lls[:reference_to])]
405
- # end
406
- # end
407
-
408
- # @param rel [Hash] relation
409
- def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
410
- return unless rel[:source_locality]&.any?
411
-
412
- rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |loc|
413
- # sls = if sl[:source_locality_stack]
414
- # RelatonBib.array(sl[:source_locality_stack]).map do |l|
415
- # SourceLocality.new(l[:type], l[:reference_from], l[:reference_to])
416
- # end
417
- # else
418
- # l = SourceLocality.new(sl[:type], sl[:reference_from], sl[:reference_to])
419
- # [l]
420
- # end
421
- SourceLocality.new loc[:type], loc[:reference_from], loc[:reference_to]
422
- end
423
- end
424
-
425
- def relaton_source_locality_stack_hash_to_bib(rel)
426
- return unless rel[:source_locality_stack]&.any?
427
-
428
- rel[:source_locality_stack] = RelatonBib.array(rel[:source_locality_stack]).map do |loc|
429
- SourceLocalityStack.new relation_source_locality_hash_to_bib(loc)
430
- end
431
- end
432
-
433
- # @param ret [Hash]
434
- def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
435
- ret[:series] = RelatonBib.array(ret[:series])&.map do |s|
436
- s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
437
- if s[:title]
438
- s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
439
- s[:title] = typed_title_strig(s[:title])
440
- end
441
- s[:abbreviation] &&
442
- s[:abbreviation] = localizedstring(s[:abbreviation])
443
- Series.new(**s)
444
- end
445
- end
446
-
447
- # @param title [Hash]
448
- # @return [RelatonBib::TypedTitleString]
449
- def typed_title_strig(title)
450
- TypedTitleString.new(**title)
451
- end
452
-
453
- # @param ret [Hash]
454
- def medium_hash_to_bib(ret)
455
- ret[:medium] = Medium.new(**ret[:medium]) if ret[:medium]
456
- end
457
-
458
- # @param ret [Hash]
459
- def classification_hash_to_bib(ret)
460
- if ret[:classification]
461
- ret[:classification] = RelatonBib.array(ret[:classification]).map do |cls|
462
- Classification.new(**cls)
463
- end
464
- end
465
- end
466
-
467
- # @param ret [Hash]
468
- def validity_hash_to_bib(ret)
469
- return unless ret[:validity]
470
-
471
- b = parse_validity_time(ret[:validity], :begins)
472
- e = parse_validity_time(ret[:validity], :ends)
473
- r = parse_validity_time(ret[:validity], :revision)
474
- ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
475
- end
476
-
477
- def parse_validity_time(val, period)
478
- t = val[period]&.to_s
479
- return unless t
480
-
481
- p = period == :ends ? -1 : 1
482
- case t
483
- when /^\d{4}$/
484
- Date.new(t.to_i, p, p).to_time
485
- when /^(?<year>\d{4})-(?<month>\d{1,2})$/
486
- Date.new($~[:year].to_i, $~[:month].to_i, p).to_time
487
- else Time.parse t
488
- end
489
- end
490
-
491
- # @param ret [Hash]
492
- def editorialgroup_hash_to_bib(ret)
493
- eg = ret.dig(:ext, :editorialgroup) || ret[:editorialgroup] # @todo remove ret[:editorialgroup] in the future
494
- return unless eg
495
-
496
- technical_committee = RelatonBib.array(eg).map do |wg|
497
- TechnicalCommittee.new WorkGroup.new(**wg)
498
- end
499
- ret[:editorialgroup] = EditorialGroup.new technical_committee
500
- end
501
-
502
- # @param ret [Hash]
503
- def ics_hash_to_bib(ret)
504
- ics = ret.dig(:ext, :ics) || ret[:ics] # @todo remove ret[:ics] in the future
505
- return unless ics
506
-
507
- ret[:ics] = RelatonBib.array(ics).map { |item| ICS.new(**item) }
508
- end
509
-
510
- # @param ret [Hash]
511
- def structuredidentifier_hash_to_bib(ret)
512
- struct_id = ret.dig(:ext, :structuredidentifier) || ret[:structuredidentifier] # @todo remove ret[:structuredidentifier] in the future
513
- return unless struct_id
514
-
515
- sids = RelatonBib.array(struct_id).map do |si|
516
- si[:agency] = RelatonBib.array si[:agency]
517
- StructuredIdentifier.new(**si)
518
- end
519
- ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
520
- end
521
-
522
- # @param ogj [Hash, Array, String]
523
- # @return [Hash, Array, String]
524
- def symbolize(obj)
525
- case obj
526
- when Hash
527
- obj.reduce({}) do |memo, (k, v)|
528
- memo[k.to_s.to_sym] = symbolize(v)
529
- memo
530
- end
531
- when Array then obj.reduce([]) { |memo, v| memo << symbolize(v) }
532
- else obj
533
- end
534
- end
535
-
536
- # @param lst [Hash, Array<RelatonBib::LocalizedString>, String]
537
- # @return [RelatonBib::LocalizedString]
538
- def localizedstring(lst)
539
- return unless lst
540
-
541
- if lst.is_a?(Hash)
542
- LocalizedString.new(lst[:content], lst[:language], lst[:script])
543
- else LocalizedString.new(lst)
544
- end
545
- end
546
-
547
- # @param frf [Hash, String]
548
- # @return [RelatonBib::FormattedRef]
549
- def formattedref(frf)
550
- if frf.is_a?(Hash)
551
- RelatonBib::FormattedRef.new(**frf)
552
- else
553
- RelatonBib::FormattedRef.new(content: frf)
554
- end
555
- end
556
-
557
- def doctype_hash_to_bib(ret)
558
- doctype = ret.dig(:ext, :doctype) || ret[:doctype] # @todo remove ret[:doctype] in the future
559
- return unless doctype
560
-
561
- ret[:doctype] = doctype.is_a?(String) ? create_doctype(type: doctype) : create_doctype(**doctype)
562
- end
563
-
564
- def create_doctype(**args)
565
- DocumentType.new(**args)
566
- end
567
- end
568
- end
@@ -1,52 +0,0 @@
1
- require "weakref"
2
-
3
- module RelatonBib
4
- class Hit
5
- # @return [RelatonBib::HitCollection]
6
- attr_accessor :hit_collection
7
-
8
- # @return [Array<Hash>]
9
- attr_reader :hit
10
-
11
- # @param hit [Hash]
12
- # @param hit_collection [RelatonBib::HitCollection]
13
- def initialize(hit, hit_collection = nil)
14
- @hit = hit
15
- @hit_collection = WeakRef.new hit_collection if hit_collection
16
- end
17
-
18
- # @return [String]
19
- def to_s
20
- inspect
21
- end
22
-
23
- # @return [String]
24
- def inspect
25
- "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} " \
26
- "@text=\"#{@hit_collection&.text}\" " \
27
- "@fetched=\"#{!@fetch.nil?}\" " \
28
- "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" " \
29
- "@title=\"#{@hit[:code]}\">"
30
- end
31
-
32
- def fetch
33
- raise "Not implemented"
34
- end
35
-
36
- # @param opts [Hash]
37
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
38
- # @option opts [Boolean] :bibdata
39
- # @option opts [String, Symbol] :lang language
40
- # @return [String] XML
41
- def to_xml(**opts)
42
- if opts[:builder]
43
- fetch.to_xml(**opts)
44
- else
45
- builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
46
- fetch.to_xml(**opts.merge(builder: xml))
47
- end
48
- builder.doc.root.to_xml
49
- end
50
- end
51
- end
52
- end