Class: RelatonBib::BibtexParser

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/bibtex_parser.rb

Overview

@todo: move this class to the RelatonBib::Bibtex module

Class Method Summary collapse

Class Method Details

.from_bibtex(bibtex) ⇒ Hash{String=>RelatonBib::BibliographicItem}

Parameters:

  • bibtex (String)

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/relaton_bib/bibtex_parser.rb', line 10

def from_bibtex(bibtex) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  BibTeX.parse(bibtex).reduce({}) do |h, bt|
    h[bt.key] = BibliographicItem.new(
      id: bt.key,
      docid: fetch_docid(bt),
      fetched: fetch_fetched(bt),
      type: fetch_type(bt),
      title: fetch_title(bt),
      contributor: fetch_contributor(bt),
      date: fetch_date(bt),
      place: fetch_place(bt),
      biblionote: fetch_note(bt),
      relation: fetch_relation(bt),
      extent: fetch_extent(bt),
      edition: bt["edition"]&.to_s,
      series: fetch_series(bt),
      link: fetch_link(bt),
      language: fetch_language(bt),
      classification: fetch_classification(bt),
      keyword: fetch_keyword(bt),
    )
    h
  end
end