Class table
STANDARD is the shipped scheme: function, product and location on, one to three letters without
I and O, and a versioned table of class codes with a short title each. The table has its own
version, independent of the library version, and the changelog names each moved code.
from refdef import STANDARD
print(STANDARD.classes.version, STANDARD.classes.depth) # 2 2
print(STANDARD.classes.get("KEB").code) # KE
print(STANDARD.classes.get("KX")) # None
get looks up the first depth letters of a code and never falls back to a shorter prefix, so
KX is unknown although K is a class.
sign_characters() gives the signs of the aspects that are on, joined in aspect order.
from refdef import Aspect
print(STANDARD.sign_characters()) # =-+
print(STANDARD.extend(aspects=[Aspect.TYPE]).sign_characters()) # =-+%
A project adds its own classes, or turns on more aspects, with extend. It returns a new scheme
and leaves STANDARD alone; an entry with a known code replaces the old one.
from refdef import Aspect, ClassEntry, Scheme, check, parse
j = STANDARD.extend(ClassEntry("J", "board connector"))
print(isinstance(j, Scheme), j.name) # True standard
P = Aspect.PRODUCT
print(check([parse("-J1", bare=P).value], j)) # ()
print([i.code.value for i in check([parse("-J1", bare=P).value], STANDARD)]) # ['unknown_class']
never bars further letters on top of the scheme's own: the new set is the union, so I and O
stay barred and extend never lifts a letter. Any iterable of letters works; a bare str is a TypeError.
strict = STANDARD.extend(never={"A"})
print([i.code.value for i in check([parse("-A1", bare=P).value], strict)]) # ['never_letter']
reserved names letters that a code should not start with, without barring them. check reports
a reserved first letter as reserved_letter, an advisory code, and STANDARD reserves none.
soft = STANDARD.extend(ClassEntry("D", "delay"), reserved={"D"})
print([i.code.value for i in check([parse("-D1", bare=P).value], soft)]) # ['reserved_letter']
print([i.code.value for i in check([parse("-K1", bare=P).value], soft)]) # []
A caller who builds its own scheme passes its own ClassTable and LetterRule, both public from refdef.
from refdef import Aspect, ClassEntry, ClassTable, LetterRule, Scheme
table = ClassTable(name="plant", version="1", depth=1, entries=(ClassEntry("A", "valve"),))
mine = Scheme("plant", frozenset({Aspect.PRODUCT}), LetterRule(1, 2, frozenset("IO")), table)
print(mine.classes.get("AB").title) # valve