Module: Blacklight::Document::Bibtex

Defined in:
app/models/concerns/blacklight/document/bibtex.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(document) ⇒ Object



17
18
19
# File 'app/models/concerns/blacklight/document/bibtex.rb', line 17

def self.extended(document)
  Blacklight::Document::Bibtex.register_export_formats(document)
end

.register_export_formats(document) ⇒ Object



21
22
23
# File 'app/models/concerns/blacklight/document/bibtex.rb', line 21

def self.register_export_formats(document)
  document.will_export_as(:bibtex, 'application/x-bibtex')
end

Instance Method Details

#export_as_bibtexObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/blacklight/document/bibtex.rb', line 25

def export_as_bibtex
  config = ::CatalogController.blacklight_config.citeproc

  entry = ::BibTeX::Entry.new
  entry.type = :book
  entry.key = id
  entry.title = first config[:fields][:title]
  multiple_valued_fields = %i[author editor]
  multiple_valued_fields.each do |field|
    entry.send("#{field}=", fetch(config[:fields][field])) if has? config[:fields][field]
  end

  single_valued_fields = %i[address annote booktitle chapter doi edition how_published institution
                            journal key month note number organization pages publisher school series url volume year]
  single_valued_fields.each do |field|
    entry.send("#{field}=", first(config[:fields][field])) if has? config[:fields][field]
  end

  entry
end