Added documentation

This commit is contained in:
Stijn Van Campenhout
2019-09-18 12:11:42 +02:00
parent 1108f87ec9
commit 2222856f4d
6 changed files with 167 additions and 42 deletions

View File

@@ -1,13 +1,17 @@
from .document import Document
from .folder import Folder
from typing import NoReturn, TypeVar
from typing import NoReturn, TypeVar, List
from .exceptions import FolderNotFound
DocOrFolder = TypeVar('DocumentOrFolder', Document, Folder)
class Collection(object):
"""
A collection of meta items
"""A collection of meta items
This is basicly the content of the Remarkable Cloud.
Attributes:
items: A list containing the items.
"""
items = []
@@ -16,18 +20,36 @@ class Collection(object):
self.items.append(i)
def add(self, docdict: dict) -> NoReturn:
"""Add an item to the collection.
It wraps it in the correct class based on the Type parameter of the
dict.
Args:
docdict: A dict representing a document or folder.
"""
if docdict.get("Type", None) == "DocumentType":
return self.addDocument(docdict)
return self.add_document(docdict)
elif docdict.get("Type", None) == "CollectionType":
return self.addFolder(docdict)
return self.add_folder(docdict)
else:
raise TypeError("Unsupported type: {_type}"
.format(_type=docdict.get("Type", None)))
def addDocument(self, docdict: dict) -> NoReturn:
def add_document(self, docdict: dict) -> NoReturn:
"""Add a document to the collection
Args:
docdict: A dict respresenting a document.
"""
self.items.append(Document(**docdict))
def addFolder(self, dirdict: dict) -> NoReturn:
def add_folder(self, dirdict: dict) -> NoReturn:
"""Add a document to the collection
Args:
dirdict: A dict respresenting a folder.
"""
self.items.append(Folder(**dirdict))
def parent(self, docorfolder: DocOrFolder) -> Folder: