Ejemplo n.º 1
0
 def __init__(self, title):
     """Initialize a new Book object with a specified title"""
     self._BEGIN = datetime.datetime.now().isoformat()
     self._END = datetime.datetime.now().isoformat()
     # Initialize Book members
     self._title = str(title).strip()
     self._author = list()
     self._meta = dict({'desc': str()})
     self._nodes = dict()
     # Create "Book Cover"
     self._nodes[self._BEGIN] = Node()
     self._nodes[self._BEGIN]._set_id(self._BEGIN)
     self._nodes[self._BEGIN].set_text("[ " + self._title + " ]")
     # Create "End Page"
     self._nodes[self._END] = Node()
     self._nodes[self._END]._set_id(self._END)
     self._nodes[self._END].set_text("The End")
     #
     return None
Ejemplo n.º 2
0
    def add_branch(self, node=None, text=None):
        """Add new node to specified existing node.

           Input Arguments:
               node - ID of node to branch off.  Default is START_OF_BOOK
               text - Text to associate with newly created node.  Default is ""

           Returns:
               ID of newly created node

        """
        node = node or self._BEGIN
        assert(node in self._nodes)
        new_node = Node()
        new_id   = new_node.get_id()
        if text is not None:
            new_node.set_text(text)
        self._nodes[new_id] = new_node
        self._nodes[node].add_link(new_id)
        return new_id
Ejemplo n.º 3
0
    def add_branch(self, node=None, text=None):
        """Add new node to specified existing node.

           Input Arguments:
               node - ID of node to branch off.  Default is START_OF_BOOK
               text - Text to associate with newly created node.  Default is ""

           Returns:
               ID of newly created node

        """
        node = node or self._BEGIN
        assert (node in self._nodes)
        new_node = Node()
        new_id = new_node.get_id()
        if text is not None:
            new_node.set_text(text)
        self._nodes[new_id] = new_node
        self._nodes[node].add_link(new_id)
        return new_id
Ejemplo n.º 4
0
    def insert_branch(self, node, break_pt):
        """Break a specified node in two, thus introducing a new branch point.

           Input Arguments:
               node     - ID of node to insert branch point
               break_pt - location in node for new branch point

           Returns:
               ID of original node

        """
        assert (node in self._nodes)
        assert (0 < break_pt < len(self._nodes[node].get_text()))
        new_node = Node()
        new_id = new_node.get_id()
        new_node.set_text(self._nodes[node].get_text()[break_pt:])
        new_node._set_links(self._nodes[node].get_links())
        self._nodes[new_id] = new_node
        self._nodes[node].set_text(self._nodes[node].get_text()[0:break_pt])
        self._nodes[node]._set_links({new_id: 0.0})
        return node
Ejemplo n.º 5
0
    def insert_branch(self, node, break_pt):
        """Break a specified node in two, thus introducing a new branch point.

           Input Arguments:
               node     - ID of node to insert branch point
               break_pt - location in node for new branch point

           Returns:
               ID of original node

        """
        assert(node in self._nodes)
        assert(0 < break_pt < len(self._nodes[node].get_text()))
        new_node = Node()
        new_id   = new_node.get_id()
        new_node.set_text(self._nodes[node].get_text()[break_pt:])
        new_node._set_links(self._nodes[node].get_links())
        self._nodes[new_id] = new_node
        self._nodes[node].set_text(self._nodes[node].get_text()[0:break_pt])
        self._nodes[node]._set_links({new_id: 0.0})
        return node