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) ⇒ Object



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

def self.download(sources, request = nil, is_public = false)
  file_path = ::Export::Bibtex.export(sources)

  ::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

.download_async(taxon_name, request = nil, is_public = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/export/bibtex.rb', line 34

def self.download_async(taxon_name, request = nil, is_public = false)
  download = ::Download.create!(
    name: name,
    description: DESCRIPTION,
    filename: filename,
    request: request,
    expires: 2.days.from_now,
    is_public: is_public
 )

  BasicNomenclatureCreateDownloadJob.perform_later(taxon_name, download)

  download
end

.export(sources) ⇒ Object



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

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

  Zip::File.open(zip_file_path, Zip::File::CREATE) do |zipfile|
    zipfile.get_output_stream('bibliography.bib') { |f| f.write  TaxonWorks::Vendor::BibtexRuby.bibliography(sources) }
  end

  zip_file_path
end

.filenameObject



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

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

.nameObject



49
50
51
# File 'lib/export/bibtex.rb', line 49

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