~mapperr/trl

36d1ec2a50af73203da8ae2f57ced6067f3539a1 — mapperr 2 years ago dcc8524
Print and match also on shortLinks and list ids
5 files changed, 29 insertions(+), 13 deletions(-)

M trullo/printer.py
M trullo/shortener.py
M trullo/trl_board.py
M trullo/trl_card.py
M trullo/trl_list.py
M trullo/printer.py => trullo/printer.py +9 -5
@@ 12,7 12,8 @@ class Printer:
    @staticmethod
    def print_boards(boards: List[TrlBoard]):
        for board in boards:
            print(f"- {board.raw_data['name']}")
            print(f"[{board.raw_data['shortLink'].lower()}] "
                  f"{board.raw_data['name']}")

    @staticmethod
    def print_board(board: TrlBoard,


@@ 31,10 32,12 @@ class Printer:
                        list_shortcuts)
                ]
            for list_ in matching_lists:
                print(f"{list_.raw_data['name']}")
                print(f"\n{list_.raw_data['name']}\n"
                      f"[{list_.raw_data['id'].lower()}]")
                for card in board.cards:
                    if card.raw_data['idList'] == list_.id:
                        print(f"\t- {card.raw_data['name']}")
                        print(f"\t[{card.raw_data['shortLink'].lower()}] "
                              f"{card.raw_data['name']}")
        print()

    @staticmethod


@@ 47,7 50,8 @@ class Printer:
        print()
        if board.lists is not None:
            for list_ in board.lists:
                print(f"- {list_.raw_data['name']}")
                print(f"[{list_.raw_data['id'].lower()}] "
                      f"{list_.raw_data['name']}")
        print()

    @staticmethod


@@ 73,5 77,5 @@ class Printer:
    def _there_is_a_match(normalized_name: str, shortcuts: List[str]) -> bool:
        return len([
            shortcut for shortcut in shortcuts
            if normalized_name.startswith(shortcut)
            if Shortener.is_a_match(shortcut, normalized_name)
        ]) > 0

M trullo/shortener.py => trullo/shortener.py +10 -4
@@ 54,8 54,14 @@ class Shortener:
        return longest_length

    @staticmethod
    def get_matches(shortcut: str,
                    shortcuttables: List[Shortcuttable]) \
            -> List[any]:
    def get_matches(
            shortcut: str,
            shortcuttables: List[Shortcuttable]) -> List[any]:
        return [shortcuttable for shortcuttable in shortcuttables
                if shortcut in shortcuttable.get_normalized_name()]
                if Shortener.is_a_match(
                shortcut, shortcuttable.get_normalized_name())
                ]

    @staticmethod
    def is_a_match(shortcut: str, normalized_name: str) -> bool:
        return shortcut in normalized_name

M trullo/trl_board.py => trullo/trl_board.py +4 -2
@@ 4,8 4,8 @@ import attr

from trullo.shortcuttable import Shortcuttable
from trullo.shortener import Shortener
from trullo.trl_list import TrlList
from trullo.trl_card import TrlCard
from trullo.trl_list import TrlList


@attr.s(auto_attribs=True)


@@ 17,4 17,6 @@ class TrlBoard(Shortcuttable):
    raw_data: Dict

    def get_normalized_name(self) -> str:
        return Shortener.normalize(self.raw_data['name'])
        return Shortener.normalize(
            f"{self.raw_data['name']}{self.raw_data['shortLink']}"
        )

M trullo/trl_card.py => trullo/trl_card.py +3 -1
@@ 13,4 13,6 @@ class TrlCard(Shortcuttable):
    raw_data: Dict

    def get_normalized_name(self):
        return Shortener.normalize(self.raw_data['name'])
        return Shortener.normalize(
            f"{self.raw_data['name']}{self.raw_data['shortLink']}"
        )

M trullo/trl_list.py => trullo/trl_list.py +3 -1
@@ 12,4 12,6 @@ class TrlList(Shortcuttable):
    raw_data: Dict

    def get_normalized_name(self) -> str:
        return Shortener.normalize(self.raw_data['name'])
        return Shortener.normalize(
            f"{self.raw_data['name']}{self.id}"
        )