Module: Export::Bibtex

Defined in:
lib/export/bibtex.rb

Overview

Exports to a simple format.

Constant Summary collapse

DESCRIPTION =
"A zip file containing a .bib export sources."

Class Method Summary collapse

Class Method Details

.download(sources, request = nil, is_public = false, style_id = 'http://www.zotero.org/styles/bibtex') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/export/bibtex.rb', line 21

def self.download(sources, request = nil, is_public = false, style_id = 'http://www.zotero.org/styles/bibtex')
  file_path = ::Export::Bibtex.export(sources, style_id)

  ::Download.create!(
    name: name,
    description: DESCRIPTION,
    filename: filename,
    source_file_path: file_path,
    request: request,
    expires: 2.days.from_now,
    is_public: is_public
  )
end

.export(sources, style_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/export/bibtex.rb', line 10

def self.export(sources, style_id)
  zip_file_path = "/tmp/_#{SecureRandom.hex(8)}_bibtex.bib"

  Zip::File.open(zip_file_path, Zip::File::CREATE) do |zipfile|
    t = style_id ? ::TaxonWorks::Vendor::BibtexRuby.styled(sources, style_id).join("\n\n") : ::TaxonWorks::Vendor::BibtexRuby.bibliography(sources)
    zipfile.get_output_stream('bibliography.bib') { |f| f.write t }
  end

  zip_file_path
end

.filenameObject



56
57
58
# File 'lib/export/bibtex.rb', line 56

def self.filename
  "bibtex_#{DateTime.now}.zip"
end

.nameObject

download end



52
53
54
# File 'lib/export/bibtex.rb', line 52

def self.name
  "Bibtex export on #{Time.now}."
end