module CFF::Citable

Methods to enable turning a CFF model or file into a citation.

The core functionality is in the citation method. In addition, each available output format has a to_{format} method generated for it as well, e.g. to_bibtex or to_apalike. These methods take a single parameter, preferred_citation:, which defaults to true as in the citation method.

Public Instance Methods

citation(format, preferred_citation: true) → String click to toggle source

Output this Index in the specified format. Setting preferred_citation: true will honour the preferred_citation field in the index if one is present (default).

format can be supplied as a String or a Symbol.

Formats that are built-in to Ruby CFF are:

  • APAlike (e.g. :apalike, 'apalike' or 'APAlike')

  • BibTeX (e.g. :bibtex, 'bibtex' or 'BibTeX')

Note: This method assumes that this Index is valid when called.

# File lib/cff/citable.rb, line 44
def citation(format, preferred_citation: true)
  formatter = Formatters.formatter_for(format)
  return '' if formatter.nil?

  formatter.format(model: self, preferred_citation: preferred_citation)
end