relaton-bib 1.20.7 → 2.0.0.pre.alpha.1

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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.adoc +183 -154
  4. data/bin/console +1 -1
  5. data/grammars/basicdoc.rng +1516 -645
  6. data/grammars/biblio-standoc.rng +100 -20
  7. data/grammars/biblio.rng +959 -356
  8. data/grammars/versions.json +10 -10
  9. data/lib/relaton/bib/hash_parser_v1.rb +711 -0
  10. data/lib/relaton/bib/item_data.rb +168 -0
  11. data/lib/relaton/bib/model/address.rb +22 -0
  12. data/lib/relaton/bib/model/affiliation.rb +16 -0
  13. data/lib/relaton/bib/model/bibdata.rb +24 -0
  14. data/lib/relaton/bib/model/bibitem.rb +23 -0
  15. data/lib/relaton/bib/model/contact.rb +18 -0
  16. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  17. data/lib/relaton/bib/model/contributor.rb +71 -0
  18. data/lib/relaton/bib/model/copyright.rb +27 -0
  19. data/lib/relaton/bib/model/date.rb +29 -0
  20. data/lib/relaton/bib/model/depiction.rb +14 -0
  21. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  22. data/lib/relaton/bib/model/doctype.rb +14 -0
  23. data/lib/relaton/bib/model/edition.rb +14 -0
  24. data/lib/relaton/bib/model/editorial_group.rb +14 -0
  25. data/lib/relaton/bib/model/ext.rb +29 -0
  26. data/lib/relaton/bib/model/extent.rb +16 -0
  27. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  28. data/lib/relaton/bib/model/fullname.rb +11 -0
  29. data/lib/relaton/bib/model/ics.rb +14 -0
  30. data/lib/relaton/bib/model/image.rb +28 -0
  31. data/lib/relaton/bib/model/item.rb +129 -0
  32. data/lib/relaton/bib/model/item_base.rb +19 -0
  33. data/lib/relaton/bib/model/keyword.rb +30 -0
  34. data/lib/relaton/bib/model/locality.rb +18 -0
  35. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  36. data/lib/relaton/bib/model/localized_string.rb +57 -0
  37. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  38. data/lib/relaton/bib/model/logo.rb +12 -0
  39. data/lib/relaton/bib/model/medium.rb +22 -0
  40. data/lib/relaton/bib/model/note.rb +16 -0
  41. data/lib/relaton/bib/model/organization.rb +13 -0
  42. data/lib/relaton/bib/model/organization_type.rb +42 -0
  43. data/lib/relaton/bib/model/person.rb +36 -0
  44. data/lib/relaton/bib/model/phone.rb +14 -0
  45. data/lib/relaton/bib/model/place.rb +33 -0
  46. data/lib/relaton/bib/model/price.rb +14 -0
  47. data/lib/relaton/bib/model/relation.rb +43 -0
  48. data/lib/relaton/bib/model/series.rb +32 -0
  49. data/lib/relaton/bib/model/size.rb +23 -0
  50. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  51. data/lib/relaton/bib/model/status.rb +27 -0
  52. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  53. data/lib/relaton/bib/model/subdivision.rb +14 -0
  54. data/lib/relaton/bib/model/technical_committee.rb +14 -0
  55. data/lib/relaton/bib/model/title.rb +18 -0
  56. data/lib/relaton/bib/model/uri.rb +18 -0
  57. data/lib/relaton/bib/model/validity.rb +16 -0
  58. data/lib/relaton/bib/model/version.rb +14 -0
  59. data/lib/relaton/bib/model/workgroup.rb +20 -0
  60. data/lib/relaton/bib/parser/rfc_address.rb +60 -0
  61. data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
  62. data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
  63. data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
  64. data/lib/relaton/bib/parser/rfc_person.rb +42 -0
  65. data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
  66. data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
  67. data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
  68. data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
  69. data/lib/relaton/bib/renderer/rfc.rb +297 -0
  70. data/lib/relaton/bib/util.rb +18 -0
  71. data/lib/relaton/bib/version.rb +5 -0
  72. data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
  73. data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
  74. data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
  75. data/lib/{relaton_bib → relaton}/hit.rb +3 -3
  76. data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
  77. data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
  78. data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
  79. data/relaton-bib.gemspec +8 -8
  80. metadata +95 -74
  81. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  82. data/lib/relaton_bib/biblio_note.rb +0 -72
  83. data/lib/relaton_bib/biblio_version.rb +0 -46
  84. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  85. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  86. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  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/document_identifier.rb +0 -118
  93. data/lib/relaton_bib/document_relation.rb +0 -95
  94. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  95. data/lib/relaton_bib/document_status.rb +0 -92
  96. data/lib/relaton_bib/document_type.rb +0 -52
  97. data/lib/relaton_bib/edition.rb +0 -55
  98. data/lib/relaton_bib/editorial_group.rb +0 -41
  99. data/lib/relaton_bib/extent.rb +0 -39
  100. data/lib/relaton_bib/forename.rb +0 -65
  101. data/lib/relaton_bib/formatted_ref.rb +0 -17
  102. data/lib/relaton_bib/formatted_string.rb +0 -133
  103. data/lib/relaton_bib/full_name.rb +0 -108
  104. data/lib/relaton_bib/hash_converter.rb +0 -568
  105. data/lib/relaton_bib/ics.rb +0 -42
  106. data/lib/relaton_bib/image.rb +0 -95
  107. data/lib/relaton_bib/localized_string.rb +0 -149
  108. data/lib/relaton_bib/medium.rb +0 -76
  109. data/lib/relaton_bib/organization.rb +0 -165
  110. data/lib/relaton_bib/person.rb +0 -129
  111. data/lib/relaton_bib/place.rb +0 -203
  112. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  113. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  114. data/lib/relaton_bib/series.rb +0 -119
  115. data/lib/relaton_bib/structured_identifier.rb +0 -173
  116. data/lib/relaton_bib/technical_committee.rb +0 -34
  117. data/lib/relaton_bib/typed_title_string.rb +0 -191
  118. data/lib/relaton_bib/typed_uri.rb +0 -57
  119. data/lib/relaton_bib/util.rb +0 -16
  120. data/lib/relaton_bib/validity.rb +0 -52
  121. data/lib/relaton_bib/version.rb +0 -3
  122. data/lib/relaton_bib/workgroup.rb +0 -58
  123. /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -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,42 +0,0 @@
1
- module RelatonBib
2
- class ICS
3
- # @return [String]
4
- attr_reader :code
5
-
6
- # @return [String, nil]
7
- attr_reader :text
8
-
9
- # @param code [String]
10
- # @param text [String, nil]
11
- def initialize(code:, text: nil)
12
- @code = code
13
- @text = text
14
- end
15
-
16
- # @param builder [Nokogiri::XML::Builder]
17
- def to_xml(builder)
18
- builder.ics do |b|
19
- b.code code
20
- b.text_ text if text
21
- end
22
- end
23
-
24
- # @return [Hash]
25
- def to_hash
26
- hash = { "code" => code }
27
- hash["text"] = text if text
28
- hash
29
- end
30
-
31
- # @param prefix [String]
32
- # @param count [Integer] number of ics
33
- # @return [String]
34
- def to_asciibib(prefix = "", count = 1)
35
- pref = prefix.empty? ? "ics" : "#{prefix}.ics"
36
- out = count > 1 ? "#{pref}::\n" : ""
37
- out += "#{pref}.code:: #{code}\n"
38
- out += "#{pref}.text:: #{text}\n" if text
39
- out
40
- end
41
- end
42
- end
@@ -1,95 +0,0 @@
1
- module RelatonBib
2
- class Image
3
- # @return [String]
4
- attr_accessor :src, :mimetype
5
-
6
- # @return [String, nil]
7
- attr_accessor :id, :filename, :width, :height, :alt, :title, :longdesc
8
-
9
- #
10
- # Initializes a new Image object.
11
- #
12
- # @param src [String] the source URL of the image
13
- # @param mimetype [String] the MIME type of the image
14
- # @param args [Hash] additional arguments
15
- # @option id [String, nil] the ID of the image
16
- # @option args [String, nil] :filename the filename of the image
17
- # @option args [String, nil] :width the width of the image
18
- # @option args [String, nil] :height the height of the image
19
- # @option args [String, nil] :alt the alternative text for the image
20
- # @option args [String, nil] :title the title of the image
21
- # @option args [String, nil] :longdesc the long description of the image
22
- #
23
- def initialize(src:, mimetype:, **args)
24
- @src = src
25
- @mimetype = mimetype
26
- args.each { |k, v| send "#{k}=", v }
27
- end
28
-
29
- def ==(other)
30
- other.is_a?(Image) && id == other.id && src == other.src && mimetype == other.mimetype &&
31
- filename == other.filename && width == other.width && height == other.height &&
32
- alt == other.alt && title == other.title && longdesc == other.longdesc
33
- end
34
-
35
- #
36
- # Converts the image object to XML format.
37
- #
38
- # @param [Nokogiri::XML::Builder] builder The XML builder object.
39
- #
40
- # @return [void]
41
- #
42
- def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
43
- builder.image do
44
- builder.parent[:id] = id if id
45
- builder.parent[:src] = src
46
- builder.parent[:mimetype] = mimetype
47
- builder.parent[:filename] = filename if filename
48
- builder.parent[:width] = width if width
49
- builder.parent[:height] = height if height
50
- builder.parent[:alt] = alt if alt
51
- builder.parent[:title] = title if title
52
- builder.parent[:longdesc] = longdesc if longdesc
53
- end
54
- end
55
-
56
- #
57
- # Converts the Image object to a hash representation.
58
- #
59
- # @return [Hash] The hash representation of the Image object.
60
- #
61
- def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
62
- hash = { "image" => { "src" => src, "mimetype" => mimetype } }
63
- hash["image"]["id"] = id if id
64
- hash["image"]["filename"] = filename if filename
65
- hash["image"]["width"] = width if width
66
- hash["image"]["height"] = height if height
67
- hash["image"]["alt"] = alt if alt
68
- hash["image"]["title"] = title if title
69
- hash["image"]["longdesc"] = longdesc if longdesc
70
- hash
71
- end
72
-
73
- #
74
- # Converts the image object to AsciiBib format.
75
- #
76
- # @param prefix [String] The prefix to be added to the AsciiBib output.
77
- #
78
- # @return [String] The image object converted to AsciiBib format.
79
- #
80
- def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
81
- pref = prefix.empty? ? "image." : "#{prefix}.image."
82
- out = ""
83
- out += "#{pref}id:: #{id}\n" if id
84
- out += "#{pref}src:: #{src}\n"
85
- out += "#{pref}mimetype:: #{mimetype}\n"
86
- out += "#{pref}filename:: #{filename}\n" if filename
87
- out += "#{pref}width:: #{width}\n" if width
88
- out += "#{pref}height:: #{height}\n" if height
89
- out += "#{pref}alt:: #{alt}\n" if alt
90
- out += "#{pref}title:: #{title}\n" if title
91
- out += "#{pref}longdesc:: #{longdesc}\n" if longdesc
92
- out
93
- end
94
- end
95
- end