-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformatter.py
More file actions
53 lines (42 loc) · 1.1 KB
/
formatter.py
File metadata and controls
53 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Module for formatter logic
"""
from enum import Enum, auto, unique
from typing import List, Dict, Callable
@unique
class Style(Enum):
"""
Class for styles logic
"""
HASH_BORDER = auto()
PLAIN_TEXT = auto()
AT_SIGN = auto()
class Styles:
STYLE_MAPPING = {
style.name.lower(): style
for style in [
Style.HASH_BORDER,
Style.PLAIN_TEXT,
Style.AT_SIGN,
]
}
@classmethod
def get_style_by_name(cls, style_name: str):
return cls.STYLE_MAPPING.get(style_name)
def show_style(chosen_style: Style, raw_input: str):
"""
Format raw_input with chosen style
"""
def show_plain(text: str):
print(text)
def show_hashborder(text: str):
print(f'###\n{text}\n###')
def show_at_sign(text: str):
print(f'@@@@ {text} @@@')
style_table: Dict[Style, Callable] = {
Style.PLAIN_TEXT: show_plain,
Style.HASH_BORDER: show_hashborder,
Style.AT_SIGN: show_at_sign,
}
styler: Callable = style_table.get(chosen_style, show_plain)
styler(raw_input)