Module: RelatonBib::HashConverter

Extended by:
HashConverter
Included in:
HashConverter
Defined in:
lib/relaton_bib/hash_converter.rb

Instance Method Summary collapse

Instance Method Details

#abstract_hash_to_bib(ret) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/relaton_bib/hash_converter.rb', line 111

def abstract_hash_to_bib(ret)
  return unless ret[:abstract]

  ret[:abstract] = RelatonBib.array(ret[:abstract]).map do |a|
    a.is_a?(String) ? FormattedString.new(content: a) : a
  end
end

#accesslocation_hash_to_bib(ret) ⇒ Object



133
134
135
136
137
# File 'lib/relaton_bib/hash_converter.rb', line 133

def accesslocation_hash_to_bib(ret)
  return unless ret[:accesslocation]

  ret[:accesslocation] = RelatonBib.array(ret[:accesslocation])
end

#affiliation_hash_to_bib(person) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/relaton_bib/hash_converter.rb', line 290

def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  return [] unless person[:affiliation]

  RelatonBib.array(person[:affiliation]).map do |a|
    a[:description] = RelatonBib.array(a[:description]).map do |d|
      cnt = if d.is_a?(Hash)
              { content: d[:content], language: d[:language],
                script: d[:script], format: d[:format] }
            else { content: d }
            end
      FormattedString.new(**cnt)
    end
    Affiliation.new(
      organization: Organization.new(**org_hash_to_bib(a[:organization])),
      description: a[:description], name: localizedstring(a[:name])
    )
  end
end

#bib_item(item_hash) ⇒ RelatonBib::BibliographicItem

Parameters:

  • item_hash (Hash)

Returns:



375
376
377
# File 'lib/relaton_bib/hash_converter.rb', line 375

def bib_item(item_hash)
  BibliographicItem.new(**item_hash)
end

#biblionote_hash_to_bib(ret) ⇒ Object

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



173
174
175
176
177
178
179
180
181
182
# File 'lib/relaton_bib/hash_converter.rb', line 173

def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  return unless ret[:biblionote]

  ret[:biblionote] = RelatonBib.array(ret[:biblionote])
    .reduce(BiblioNoteCollection.new([])) do |mem, n|
    mem << if n.is_a?(String) then BiblioNote.new content: n
            else BiblioNote.new(**n)
            end
  end
end

#classification_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


459
460
461
462
463
464
465
# File 'lib/relaton_bib/hash_converter.rb', line 459

def classification_hash_to_bib(ret)
  if ret[:classification]
    ret[:classification] = RelatonBib.array(ret[:classification]).map do |cls|
      Classification.new(**cls)
    end
  end
end

#contacts_hash_to_bib(entity) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/relaton_bib/hash_converter.rb', line 309

def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
  return [] unless entity[:contact]

  RelatonBib.array(entity[:contact]).map do |a|
    type, value = a.reject { |k, _| k == :type }.flatten
    case type
    when :street, :city, :state, :country, :postcode # it's for old version compatibility, should be removed in the future
      a[:street] = RelatonBib.array(a[:street])
      Address.new(**a)
    when :address then create_address(a[:address])
    when :phone, :email, :uri
      Contact.new(type: type.to_s, value: value, subtype: a[:type])
    else # it's for old version compatibility, should be removed in the future
      Contact.new(**a)
    end
  end
end

#contributors_hash_to_bib(ret) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/relaton_bib/hash_converter.rb', line 206

def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
  return unless ret[:contributor]

  ret[:contributor] = RelatonBib.array(ret[:contributor])
  ret[:contributor]&.each_with_index do |c, i|
    roles = RelatonBib.array(ret[:contributor][i][:role]).map do |r|
      if r.is_a? Hash
        desc = RelatonBib.array(r[:description]).map { |d| d.is_a?(String) ? d : d[:content] }
        { type: r[:type], description: desc }
      # elsif r.is_a? Array
      #   { type: r[0], description: r.fetch(1) }
      else
        { type: r }
      end
    end
    ret[:contributor][i][:role] = roles
    ret[:contributor][i][:entity] = if c[:person]
                                      person_hash_to_bib(c[:person])
                                    else
                                      org_hash_to_bib(c[:organization])
                                    end
    ret[:contributor][i].delete(:person)
    ret[:contributor][i].delete(:organization)
  end
end

Parameters:

  • ret (Hash)


337
338
339
340
341
342
343
344
345
346
# File 'lib/relaton_bib/hash_converter.rb', line 337

def copyright_hash_to_bib(ret)
  return unless ret[:copyright]

  ret[:copyright] = RelatonBib.array(ret[:copyright]).map do |c|
    c[:owner] = RelatonBib.array(c[:owner]).map do |o|
      org_hash_to_bib(o)
    end
    c
  end
end

#create_address(adr) ⇒ Object



327
328
329
330
331
332
333
334
# File 'lib/relaton_bib/hash_converter.rb', line 327

def create_address(adr)
  if adr.is_a?(Hash)
    adr[:street] = RelatonBib.array(adr[:street])
    Address.new(**adr)
  else
    Address.new(formatted_address: adr)
  end
end

#create_docid(**args) ⇒ Object



161
162
163
# File 'lib/relaton_bib/hash_converter.rb', line 161

def create_docid(**args)
  DocumentIdentifier.new(**args)
end

#create_doctype(**args) ⇒ Object



564
565
566
# File 'lib/relaton_bib/hash_converter.rb', line 564

def create_doctype(**args)
  DocumentType.new(**args)
end

#dates_hash_to_bib(ret) ⇒ Object

rubocop:disable Metrics/AbcSize



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/relaton_bib/hash_converter.rb', line 139

def dates_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
  return unless ret[:date]

  ret[:date] = RelatonBib.array(ret[:date])
  ret[:date].each_with_index do |d, i|
    # value is synonym of on: it is reserved word in YAML
    if d[:value]
      ret[:date][i][:on] ||= d[:value]
      ret[:date][i].delete(:value)
    end
  end
end

#docid_hash_to_bib(ret) ⇒ Object

rubocop:disable Metrics/AbcSize



152
153
154
155
156
157
158
159
# File 'lib/relaton_bib/hash_converter.rb', line 152

def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
  return unless ret[:docid]

  ret[:docid] = RelatonBib.array(ret[:docid]).map do |id|
    id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
    create_docid(**id)
  end
end

#docstatus_hash_to_bib(ret) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/relaton_bib/hash_converter.rb', line 189

def docstatus_hash_to_bib(ret)
  ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
    stage: stage(ret[:docstatus][:stage]),
    substage: stage(ret[:docstatus][:substage]),
    iteration: ret[:docstatus][:iteration],
  )
end

#doctype_hash_to_bib(ret) ⇒ Object



557
558
559
560
561
562
# File 'lib/relaton_bib/hash_converter.rb', line 557

def doctype_hash_to_bib(ret)
  doctype = ret.dig(:ext, :doctype) || ret[:doctype] # @todo remove ret[:doctype] in the future
  return unless doctype

  ret[:doctype] = doctype.is_a?(String) ? create_doctype(type: doctype) : create_doctype(**doctype)
end

#editorialgroup_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


492
493
494
495
496
497
498
499
500
# File 'lib/relaton_bib/hash_converter.rb', line 492

def editorialgroup_hash_to_bib(ret)
  eg = ret.dig(:ext, :editorialgroup) || ret[:editorialgroup] # @todo remove ret[:editorialgroup] in the future
  return unless eg

  technical_committee = RelatonBib.array(eg).map do |wg|
    TechnicalCommittee.new WorkGroup.new(**wg)
  end
  ret[:editorialgroup] = EditorialGroup.new technical_committee
end

#ext_has_to_bib(ret) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/relaton_bib/hash_converter.rb', line 43

def ext_has_to_bib(ret)
  doctype_hash_to_bib ret
  ret[:subdoctype] = ret[:ext][:subdoctype] if ret.dig(:ext, :subdoctype)
  editorialgroup_hash_to_bib ret
  ics_hash_to_bib ret
  structuredidentifier_hash_to_bib ret
end

#extent_hash_to_bib(ret) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/relaton_bib/hash_converter.rb', line 57

def extent_hash_to_bib(ret)
  return unless ret[:extent]

  ret[:extent] = RelatonBib.array(ret[:extent]).map do |e|
    RelatonBib::Extent.new locality(e)
  end
end

#forename_hash_to_bib(fname) ⇒ Object



277
278
279
280
281
282
# File 'lib/relaton_bib/hash_converter.rb', line 277

def forename_hash_to_bib(fname)
  case fname
  when Hash then Forename.new(**fname)
  when String then Forename.new(content: fname)
  end
end

#formattedref(frf) ⇒ RelatonBib::FormattedRef

Parameters:

  • frf (Hash, String)

Returns:



549
550
551
552
553
554
555
# File 'lib/relaton_bib/hash_converter.rb', line 549

def formattedref(frf)
  if frf.is_a?(Hash)
    RelatonBib::FormattedRef.new(**frf)
  else
    RelatonBib::FormattedRef.new(content: frf)
  end
end

#formattedref_hash_to_bib(ret) ⇒ Object



184
185
186
187
# File 'lib/relaton_bib/hash_converter.rb', line 184

def formattedref_hash_to_bib(ret)
  ret[:formattedref] &&
    ret[:formattedref] = formattedref(ret[:formattedref])
end

#fullname_hash_to_bib(person) ⇒ Object

rubocop:disable Metrics/AbcSize



256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/relaton_bib/hash_converter.rb', line 256

def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize
  n = person[:name]
  fname, inits = given_hash_to_bib n[:given] || n # `n` is for backward compatibility
  FullName.new(
    abbreviation: localizedstring(n[:abbreviation]),
    forename: fname, initials: inits,
    addition: RelatonBib.array(n[:addition])&.map { |f| localizedstring(f) },
    prefix: RelatonBib.array(n[:prefix])&.map { |f| localizedstring(f) },
    surname: localizedstring(n[:surname]),
    completename: localizedstring(n[:completename])
  )
end

#given_hash_to_bib(given) ⇒ Object



269
270
271
272
273
274
275
# File 'lib/relaton_bib/hash_converter.rb', line 269

def given_hash_to_bib(given)
  return [[], nil] unless given

  fname = RelatonBib.array(given[:forename])&.map { |f| forename_hash_to_bib(f) }
  inits = localizedstring(given[:formatted_initials])
  [fname, inits]
end

#hash_to_bib(args) ⇒ Hash

Parameters:

  • args (Hash)

Returns:

  • (Hash)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/relaton_bib/hash_converter.rb', line 6

def hash_to_bib(args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  return nil unless args.is_a?(Hash)

  ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
  title_hash_to_bib(ret)
  link_hash_to_bib(ret)
  language_hash_to_bib(ret)
  script_hash_to_bib(ret)
  dates_hash_to_bib(ret)
  docid_hash_to_bib(ret)
  version_hash_to_bib(ret)
  biblionote_hash_to_bib(ret)
  abstract_hash_to_bib(ret)
  formattedref_hash_to_bib(ret)
  docstatus_hash_to_bib(ret)
  contributors_hash_to_bib(ret)
  copyright_hash_to_bib(ret)
  relations_hash_to_bib(ret)
  series_hash_to_bib(ret)
  medium_hash_to_bib(ret)
  place_hash_to_bib(ret)
  extent_hash_to_bib(ret)
  size_hash_to_bib(ret)
  accesslocation_hash_to_bib(ret)
  classification_hash_to_bib(ret)
  validity_hash_to_bib(ret)
  keyword_hash_to_bib(ret)
  # ret[:keyword] = RelatonBib.array(ret[:keyword])
  ret[:license] = RelatonBib.array(ret[:license])
  # editorialgroup_hash_to_bib ret
  # ics_hash_to_bib ret
  # structuredidentifier_hash_to_bib ret
  # doctype_hash_to_bib ret
  ext_has_to_bib ret
  ret
end

#ics_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


503
504
505
506
507
508
# File 'lib/relaton_bib/hash_converter.rb', line 503

def ics_hash_to_bib(ret)
  ics = ret.dig(:ext, :ics) || ret[:ics] # @todo remove ret[:ics] in the future
  return unless ics

  ret[:ics] = RelatonBib.array(ics).map { |item| ICS.new(**item) }
end

#keyword_hash_to_bib(ret) ⇒ Object



51
52
53
54
55
# File 'lib/relaton_bib/hash_converter.rb', line 51

def keyword_hash_to_bib(ret)
  ret[:keyword] = RelatonBib.array(ret[:keyword]).map do |keyword|
    localizedstring keyword
  end
end

#language_hash_to_bib(ret) ⇒ Object



99
100
101
102
103
# File 'lib/relaton_bib/hash_converter.rb', line 99

def language_hash_to_bib(ret)
  return unless ret[:language]

  ret[:language] = RelatonBib.array(ret[:language])
end


119
120
121
122
123
# File 'lib/relaton_bib/hash_converter.rb', line 119

def link_hash_to_bib(ret)
  return unless ret[:link]

  ret[:link] = RelatonBib.array(ret[:link])
end

#locality(loc) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/relaton_bib/hash_converter.rb', line 65

def locality(loc)
  if loc[:locality_stack]
    RelatonBib.array(loc[:locality_stack]).map do |l|
      LocalityStack.new locality(l)
    end
  else
    RelatonBib.array(loc[:locality]).map do |l|
      Locality.new(l[:type], l[:reference_from], l[:reference_to])
    end
  end
end

#localizedstring(lst) ⇒ RelatonBib::LocalizedString

Parameters:

Returns:



538
539
540
541
542
543
544
545
# File 'lib/relaton_bib/hash_converter.rb', line 538

def localizedstring(lst)
  return unless lst

  if lst.is_a?(Hash)
    LocalizedString.new(lst[:content], lst[:language], lst[:script])
  else LocalizedString.new(lst)
  end
end

#medium_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


454
455
456
# File 'lib/relaton_bib/hash_converter.rb', line 454

def medium_hash_to_bib(ret)
  ret[:medium] = Medium.new(**ret[:medium]) if ret[:medium]
end

#org_hash_to_bib(org) ⇒ Object

rubocop:disable Metrics/AbcSize



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/relaton_bib/hash_converter.rb', line 232

def org_hash_to_bib(org) # rubocop:disable Metrics/AbcSize
  return nil if org.nil?

  org[:identifier] = RelatonBib.array(org[:identifier])&.map do |a|
    OrgIdentifier.new(a[:type], a[:id])
  end
  org[:subdivision] = RelatonBib.array(org[:subdivision]).map do |sd|
    LocalizedString.new sd.is_a?(Hash) ? sd[:content] : sd
  end
  org[:contact] = contacts_hash_to_bib(org)
  org[:logo] = Image.new(**org[:logo][:image]) if org[:logo]
  org
end

#parse_validity_time(val, period) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/relaton_bib/hash_converter.rb', line 477

def parse_validity_time(val, period)
  t = val[period]&.to_s
  return unless t

  p = period == :ends ? -1 : 1
  case t
  when /^\d{4}$/
    Date.new(t.to_i, p, p).to_time
  when /^(?<year>\d{4})-(?<month>\d{1,2})$/
    Date.new($~[:year].to_i, $~[:month].to_i, p).to_time
  else Time.parse t
  end
end

#person_hash_to_bib(person) ⇒ Object



246
247
248
249
250
251
252
253
254
# File 'lib/relaton_bib/hash_converter.rb', line 246

def person_hash_to_bib(person)
  Person.new(
    name: fullname_hash_to_bib(person),
    credential: RelatonBib.array(person[:credential]),
    affiliation: affiliation_hash_to_bib(person),
    contact: contacts_hash_to_bib(person),
    identifier: person_identifiers_hash_to_bib(person),
  )
end

#person_identifiers_hash_to_bib(person) ⇒ Object



284
285
286
287
288
# File 'lib/relaton_bib/hash_converter.rb', line 284

def person_identifiers_hash_to_bib(person)
  RelatonBib.array(person[:identifier])&.map do |a|
    PersonIdentifier.new(a[:type], a[:id])
  end
end

#place_hash_to_bib(ret) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/relaton_bib/hash_converter.rb', line 125

def place_hash_to_bib(ret)
  return unless ret[:place]

  ret[:place] = RelatonBib.array(ret[:place]).map do |pl|
    pl.is_a?(String) ? Place.new(name: pl) : Place.new(**pl)
  end
end

#relation_bibitem_hash_to_bib(rel) ⇒ Object

Parameters:

  • rel (Hash)

    relation



364
365
366
367
368
369
370
371
# File 'lib/relaton_bib/hash_converter.rb', line 364

def relation_bibitem_hash_to_bib(rel)
  if rel[:bibitem]
    rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem])
  else
    Util.warn "Bibitem missing: `#{rel}`"
    rel[:bibitem] = nil
  end
end

#relation_locality_hash_to_bib(rel) ⇒ RelatonBib::LocalityStack

Parameters:

  • rel (Hash)

    relation

Returns:



381
382
383
384
385
386
387
# File 'lib/relaton_bib/hash_converter.rb', line 381

def relation_locality_hash_to_bib(rel)
  return unless rel[:locality]&.any?

  rel[:locality] = RelatonBib.array(rel[:locality]).map do |bl|
    Locality.new(bl[:type], bl[:reference_from], bl[:reference_to])
  end
end

#relation_locality_stack_hash_to_bib(rel) ⇒ Object



389
390
391
392
393
394
395
# File 'lib/relaton_bib/hash_converter.rb', line 389

def relation_locality_stack_hash_to_bib(rel)
  return unless rel[:locality_stack]&.any?

  rel[:locality_stack] = RelatonBib.array(rel[:locality_stack]).map do |ls|
    LocalityStack.new relation_locality_hash_to_bib(ls)
  end
end

#relation_source_locality_hash_to_bib(rel) ⇒ Object

Parameters:

  • rel (Hash)

    relation



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/relaton_bib/hash_converter.rb', line 409

def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  return unless rel[:source_locality]&.any?

  rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |loc|
    # sls = if sl[:source_locality_stack]
    #         RelatonBib.array(sl[:source_locality_stack]).map do |l|
    #           SourceLocality.new(l[:type], l[:reference_from], l[:reference_to])
    #         end
    #       else
    #         l = SourceLocality.new(sl[:type], sl[:reference_from], sl[:reference_to])
    #         [l]
    #       end
    SourceLocality.new loc[:type], loc[:reference_from], loc[:reference_to]
  end
end

#relations_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/relaton_bib/hash_converter.rb', line 349

def relations_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  return unless ret[:relation]

  ret[:relation] = RelatonBib.array(ret[:relation])
  ret[:relation]&.each do |rel|
    rel[:description] = FormattedString.new(**rel[:description]) if rel[:description]
    relation_bibitem_hash_to_bib(rel)
    relation_locality_hash_to_bib(rel)
    relation_locality_stack_hash_to_bib(rel)
    relation_source_locality_hash_to_bib(rel)
    relaton_source_locality_stack_hash_to_bib(rel)
  end
end

#relaton_source_locality_stack_hash_to_bib(rel) ⇒ Object



425
426
427
428
429
430
431
# File 'lib/relaton_bib/hash_converter.rb', line 425

def relaton_source_locality_stack_hash_to_bib(rel)
  return unless rel[:source_locality_stack]&.any?

  rel[:source_locality_stack] = RelatonBib.array(rel[:source_locality_stack]).map do |loc|
    SourceLocalityStack.new relation_source_locality_hash_to_bib(loc)
  end
end

#script_hash_to_bib(ret) ⇒ Object



105
106
107
108
109
# File 'lib/relaton_bib/hash_converter.rb', line 105

def script_hash_to_bib(ret)
  return unless ret[:script]

  ret[:script] = RelatonBib.array(ret[:script])
end

#series_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/relaton_bib/hash_converter.rb', line 434

def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  ret[:series] = RelatonBib.array(ret[:series])&.map do |s|
    s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
    if s[:title]
      s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
      s[:title] = typed_title_strig(s[:title])
    end
    s[:abbreviation] &&
      s[:abbreviation] = localizedstring(s[:abbreviation])
    Series.new(**s)
  end
end

#size_hash_to_bib(ret) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/relaton_bib/hash_converter.rb', line 77

def size_hash_to_bib(ret)
  return unless ret[:size]

  ret[:size] = RelatonBib.array(ret[:size])
  size = ret[:size]&.map do |val|
    BibliographicSize::Value.new(**val)
  end
  ret[:size] = BibliographicSize.new(size)
end

#stage(stg) ⇒ RelatonBib::DocumentStatus::Stage

Parameters:

  • stg (Hash)

Returns:



199
200
201
202
203
204
# File 'lib/relaton_bib/hash_converter.rb', line 199

def stage(stg)
  return unless stg

  args = stg.is_a?(String) ? { value: stg } : stg
  DocumentStatus::Stage.new(**args)
end

#structuredidentifier_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


511
512
513
514
515
516
517
518
519
520
# File 'lib/relaton_bib/hash_converter.rb', line 511

def structuredidentifier_hash_to_bib(ret)
  struct_id = ret.dig(:ext, :structuredidentifier) || ret[:structuredidentifier] # @todo remove ret[:structuredidentifier] in the future
  return unless struct_id

  sids = RelatonBib.array(struct_id).map do |si|
    si[:agency] = RelatonBib.array si[:agency]
    StructuredIdentifier.new(**si)
  end
  ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
end

#symbolize(obj) ⇒ Hash, ...

Parameters:

  • ogj (Hash, Array, String)

Returns:



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/relaton_bib/hash_converter.rb', line 524

def symbolize(obj)
  case obj
  when Hash
    obj.reduce({}) do |memo, (k, v)|
      memo[k.to_sym] = symbolize(v)
      memo
    end
  when Array then obj.reduce([]) { |memo, v| memo << symbolize(v) }
  else obj
  end
end

#title_hash_to_bib(ret) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/relaton_bib/hash_converter.rb', line 87

def title_hash_to_bib(ret)
  return unless ret[:title]

  ret[:title] = RelatonBib.array(ret[:title])
    .reduce(TypedTitleStringCollection.new) do |m, t|
    if t.is_a?(Hash) then m << TypedTitleString.new(**t)
    else
      m + TypedTitleString.from_string(t)
    end
  end
end

#typed_title_strig(title) ⇒ RelatonBib::TypedTitleString

Parameters:

  • title (Hash)

Returns:



449
450
451
# File 'lib/relaton_bib/hash_converter.rb', line 449

def typed_title_strig(title)
  TypedTitleString.new(**title)
end

#validity_hash_to_bib(ret) ⇒ Object

Parameters:

  • ret (Hash)


468
469
470
471
472
473
474
475
# File 'lib/relaton_bib/hash_converter.rb', line 468

def validity_hash_to_bib(ret)
  return unless ret[:validity]

  b = parse_validity_time(ret[:validity], :begins)
  e = parse_validity_time(ret[:validity], :ends)
  r = parse_validity_time(ret[:validity], :revision)
  ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
end

#version_hash_to_bib(ret) ⇒ Object



165
166
167
168
169
170
171
# File 'lib/relaton_bib/hash_converter.rb', line 165

def version_hash_to_bib(ret)
  return unless ret[:version]

  ret[:version] = RelatonBib.array(ret[:version]).map do |v|
    BibliographicItem::Version.new(v[:revision_date], v[:draft])
  end
end