Wrote documentation for every func/class in .py

This commit is contained in:
Kiryl
2021-12-10 10:53:40 +03:00
parent ef3502cd0a
commit 4b1109e6b4
13 changed files with 198 additions and 172 deletions

View File

@@ -2,21 +2,22 @@ import re
from typing import Union
from ebooklib.epub import Section, Link
from src.livecarta_config import LiveCartaConfig
"""
These are data structures which form mapping from NCX to python data structures.
"""
class NavPoint:
"""
Class - Navigation Point, - every html|xhtml from epub
These are data structures which form mapping from NCX to python data structures.
"""
def __init__(self, obj: Union[Link, Section] = None, ):
self.href, self.id = self.parse_href_id(obj)
self.title = obj.title
@staticmethod
def parse_href_id(item: Union[Link, Section]):
"""Function parses href & id from item.href"""
reg = r'(.+\..+\#)(.+)'
match = re.search(reg, item.href)
href, div_id = None, None
@@ -36,13 +37,8 @@ class NavPoint:
return '<NavPoint: %s, %s>' % (self.href, self.id)
"""
These are data structures which form mapping to livecarta json structure.
"""
def flatten(x):
""" magic function from stackoverflow for list flattening """
"""magic function from stackoverflow for list flattening"""
atom = lambda i: not isinstance(i, list)
nil = lambda i: not i
car = lambda i: i[0]
@@ -54,12 +50,18 @@ def flatten(x):
class ChapterItem:
"""
Class of Chapter that could have subchapters
These are data structures which form mapping to livecarta json structure.
"""
def __init__(self, title, content, sub_items):
self.title = title
self.content = content
self.sub_items = sub_items
def to_dict(self, lvl=1):
"""Function returns dictionary of chapter"""
sub_dicts = []
if self.sub_items:
for i in self.sub_items:
@@ -86,4 +88,4 @@ class ChapterItem:
}
def __str__(self):
return '<Chapter: %s>' % self.title
return '<Chapter: %s>' % self.title