The URIFormatter class¶
- class ferenda.URIFormatter(*formatters)¶
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 a pyparsing.ParseResult object (which has a .getName method), 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.
Parameters: *formatters (list) – Formatters, each provided as a (name, callable) tuple.
Given a pyparsing.ParseResult object, finds a appropriate formatter for that result, and formats the result into a URI using that formatter.
- addformatter(key, func)¶
Add a single formatter to the list of registered formatters after initialization.
Returns an appropriate formatting callable for the given key, or None if not found.