Module: Serializers::BibTex
- Included in:
- Document
- Defined in:
- lib/serializers/bib_tex.rb
Overview
Convert a document to a BibTeX record
Class Method Summary (collapse)
-
+ (Object) included(base)
Register this serializer in the Document list.
Instance Method Summary (collapse)
-
- (String) to_bibtex
Returns this document as a BibTeX record.
Class Method Details
+ (Object) included(base)
Register this serializer in the Document list
9 10 11 12 |
# File 'lib/serializers/bib_tex.rb', line 9 def self.included(base) base.register_serializer(:bibtex, 'BibTeX', lambda { |doc| doc.to_bibtex }, 'http://mirrors.ctan.org/biblio/bibtex/contrib/doc/btxdoc.pdf') end |
Instance Method Details
- (String) to_bibtex
Returns this document as a BibTeX record
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/serializers/bib_tex.rb', line 20 def to_bibtex # We don't have a concept of cite keys, so we're forced to just use # AuthorYear and hope it doesn't collide if .nil? || .count == 0 = 'Anon' else = [0].last.gsub(' ','').gsub(/[^A-za-z0-9_]/, '') end cite_key = "#{}#{year}" ret = "@article{#{cite_key},\n" unless .nil? || .count == 0 ret << " author = {#{.join(' and ')}},\n" end ret << " title = {#{title}},\n" unless title.blank? ret << " journal = {#{journal}},\n" unless journal.blank? ret << " volume = {#{volume}},\n" unless volume.blank? ret << " number = {#{number}},\n" unless number.blank? ret << " pages = {#{pages}},\n" unless pages.blank? ret << " doi = {#{doi}},\n" unless doi.blank? ret << " year = {#{year}}\n" unless year.blank? ret << "}\n" ret end |