from scheduler.block import BaseBlock class BooleanParser(BaseBlock): def __init__(self, true_text: str, false_text: str): super(BooleanParser, self).__init__() self.true_text = true_text self.false_text = false_text def __call__(self, text: str) -> bool: if text == self.true_text: return True elif text == self.false_text: return False else: return None class ListParser(BaseBlock): def __init__(self, delim: str, prefix="", suffix=""): super(ListParser, self).__init__() self.delim = delim self.prefix = prefix self.suffix = suffix def __call__(self, text: str) -> list: text = text.strip().lstrip(self.prefix).rstrip(self.suffix) return [t.strip() for t in text.split(self.delim) if t.strip()]