module CFF::Formatters
A registry of output formatters for converting CFF
files into citations.
Public Class Methods
formatters → Array
click to toggle source
Return the list of formatters that are available.
# File lib/cff/formatters.rb, line 27 def self.formatters @formatters.keys end
register_formatter(class)
click to toggle source
Register a citation formatter. To be registered as a formatter, a class should at least provide the following class methods:
-
format
, which takes the model to be formatted as a named parameter, and the option to cite aCFF
file’spreferred-citation
:def self.format(model:, preferred_citation: true); end
-
label
, which returns a short name for the formatter, e.g.'BibTeX'
. If your formatter class subclassesCFF::Formatter
, thenlabel
is provided for you.
# File lib/cff/formatters.rb, line 46 def self.register_formatter(clazz) return unless clazz.singleton_methods.include?(:format) return if @formatters.has_value?(clazz) format = clazz.label.downcase.to_sym @formatters[format] = clazz Citable.add_to_format_method(format) if defined?(Citable) end