From 5dc0aa72f42d1e45a9f9c8abfd68b560330ced27 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Sun, 29 Nov 2020 17:06:15 -0500 Subject: [PATCH] Update docs --- api/ECNQueue.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 6ee4122..881fb4b 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -83,11 +83,13 @@ def isValidItemName(name: str) -> bool: # Classes #------------------------------------------------------------------------------# class Item: - """A single whole issue or jsut the issues header information. + """A chronological representation of an interaction with a user. Example: # Create an Item (ce100) >>> item = Item("ce", 100, headersOnly=false) + # Create an Item without parsing its contents (ce100) + >>> item = Item("ce", 100, headersOnly=True) Attributes: lastUpdated: An ISO 8601 formatted time string showing the last time the file was updated according to the filesystem. @@ -104,17 +106,17 @@ class Item: department: The most recent department for this item. dateReceived: The date this item was created. jsonData: A JSON serializable representation of the Item. + + Raises: + ValueError: When the number passed to the constructor cannot be parsed. """ def __init__(self, queue: str, number: int, headersOnly: bool = False) -> None: self.queue = queue - try: self.number = int(number) except ValueError: - raise ValueError(" Could not convert \"" + - number + "\" to an integer") - + raise ValueError(f'Could not convert "{number}" to an integer') self.__path = "/".join([queueDirectory, self.queue, str(self.number)]) self.lastUpdated = self.__getLastUpdated() self.__rawItem = self.__getRawItem() @@ -130,8 +132,7 @@ def __init__(self, queue: str, number: int, headersOnly: bool = False) -> None: self.priority = self.__getMostRecentHeaderByType("Priority") self.department = self.__getMostRecentHeaderByType("Department") self.building = self.__getMostRecentHeaderByType("Building") - self.dateReceived = self.__getFormattedDate( - self.__getMostRecentHeaderByType("Date")) + self.dateReceived = self.__getFormattedDate(self.__getMostRecentHeaderByType("Date")) self.jsonData = {} for attribute in self.__dir__(): @@ -1197,11 +1198,13 @@ def __repr__(self) -> str: # TODO: Make Queue iterable using __iter__. See: https://thispointer.com/python-how-to-make-a-class-iterable-create-iterator-class-for-it/ class Queue: - """A collection of items. + """A collection of Items. Example: # Create a queue (ce) >>> queue = Queue("ce") + # Create a queue without parsing item contents (ce) + >>> queue = Queue("ce", headersOnly=False) Attributes: name: The name of the queue. @@ -1306,12 +1309,20 @@ def getQueueCounts() -> list: queueInfo.append( {"name": queue, "number_of_items": len(validItems)} ) return queueInfo - def loadAllQueues(headersOnly: bool = True) -> list: """Return a list of Queues for each queue. + Example: + # Load all Queues without parsing Item content + >>> loadAllQueues(); + Load all Queues and parsing Item content + >>> loadAllQueues(headersOnly=False) + + Args: + headersOnly (bool, optional): Whether or not to parse headers only. Defaults to True. + Returns: - list: list of Queues for each queue. + list: List of Queues for each queue. """ queues = []