The URIFormatter class¶
-
class
ferenda.URIFormatter(*formatters)[source]¶ Companion class to
ferenda.CitationParser, that handles the work of formatting the dicts or dict-like objects that CitationParser creates.The class is initialized with a list of formatters, where each formatter is a tuple (key, callable). When
format()is passed a citation reference in the form of apyparsing.ParseResultobject (which has a.getNamemethod), the name of that reference is matched against the key of all formatters. If there is a match, the corresponding callable is called with the parseresult object as a single parameter, and the resulting string is returned.An initialized
URIFormatterobject is not used directly. Instead, callferenda.CitationParser.set_formatter()with the object as parameter. See Citation parsing.Parameters: *formatters (list) – Formatters, each provided as a (name, callable) tuple. -
format(parseresult)[source]¶ Given a pyparsing.ParseResult object, finds a appropriate formatter for that result, and formats the result into a URI using that formatter.
-