Class: Arxiv::Downloader::Bibtex

Inherits:
Object
  • Object
show all
Defined in:
lib/arxiv/downloader/bibtex.rb

Instance Method Summary collapse

Constructor Details

#initialize(metadata, client: nil) ⇒ Bibtex

Returns a new instance of Bibtex.



4
5
6
7
# File 'lib/arxiv/downloader/bibtex.rb', line 4

def initialize , client: nil
  @metadata = 
  @client   = client
end

Instance Method Details

#fetchObject



23
24
25
26
27
28
29
30
# File 'lib/arxiv/downloader/bibtex.rb', line 23

def fetch
  return nil if @client.nil?

  response = @client.get url
  return nil unless response.status.success?

  response.to_s
end

#keyObject



36
37
38
39
40
41
42
# File 'lib/arxiv/downloader/bibtex.rb', line 36

def key
  last_name  = @metadata.authors.first.split.last.downcase.gsub(/[^a-z]/, '')
  year       = @metadata.published.year
  title_word = Slug.new(@metadata.title).to_s.split('-').first

  "#{last_name}#{year}#{title_word}"
end

#synthesizeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/arxiv/downloader/bibtex.rb', line 9

def synthesize
  <<~BIBTEX
    @misc{#{key},
      title={#{@metadata.title}},
      author={#{authors}},
      year={#{@metadata.published.year}},
      eprint={#{@metadata.arxiv_id}},
      archivePrefix={arXiv},
      primaryClass={#{@metadata.primary_category[:id]}},
      url={#{@metadata.arxiv_url}},
    }
  BIBTEX
end

#to_sObject



32
33
34
# File 'lib/arxiv/downloader/bibtex.rb', line 32

def to_s
  fetch || synthesize
end