Statistics visitor class
Definition at line 51 of file online_book_statistics.py.
◆ __init__()
Initialize class
Definition at line 66 of file online_book_statistics.py.
66 def __init__(self):
67 """Initialize class"""
68
69 self.statistics = Statistics()
70
◆ read_rst_file()
read_rst_file |
( |
| self, |
|
|
Path | path ) |
Read rst file
Definition at line 71 of file online_book_statistics.py.
71 def read_rst_file(self, path: Path):
72 """Read rst file"""
73 text = path.read_text()
74 self.statistics.characters += len(text)
75 for line in text.split("\n"):
76 for key, regex in self.regexes.items():
77 if regex.findall(line):
78 setattr(
79 self.statistics, key, getattr(self.statistics, key) + 1
80 )
81
◆ walk_directory()
walk_directory |
( |
| self, |
|
|
Path | path ) |
Loop over all directories in the path
Definition at line 82 of file online_book_statistics.py.
82 def walk_directory(self, path: Path):
83 """Loop over all directories in the path"""
84 print(f"Walking {path}")
85 for root, _, files in os.walk(path):
86 for file in files:
87 path = Path(root) / file
88 if path.suffix == ".rst":
89 self.read_rst_file(path)
90
91
◆ regexes
Initial value:= dict(
code_inclusions=re.compile("(code-block\\s*::)|(literalinclude\\s*::)"),
hints=re.compile(":class:.*hint"),
solutions=re.compile(":class:.*solution"),
exercises=re.compile(":class:.*exercise"),
overview_boxes=re.compile(":class:.*overview"),
key_points=re.compile(":class:.*key-points"),
figures=re.compile("figure\\s*::")
)
Dictionary keys must match attributes of Statistics class.
Definition at line 56 of file online_book_statistics.py.
◆ statistics
The documentation for this class was generated from the following file: