Completed
Pull Request — master (#43)
by Oleg
02:07
created

TocNode   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 37.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
dl 0
loc 60
ccs 6
cts 16
cp 0.375
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A is_inline_command() 0 7 1
A get_command() 0 7 1
A is_block_command() 0 7 1
A __init__() 0 9 1
A generate_toc() 0 16 4
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9 1
from sdoc.sdoc2 import node_store
10 1
from sdoc.sdoc2.node.Node import Node
11 1
from sdoc.sdoc2.node.HeadingNode import HeadingNode
12 1
from sdoc.sdoc2.node.ParagraphNode import ParagraphNode
13
14
15 1
class TocNode(Node):
16
    """
17
    SDoc2 node for table of contents.
18
    """
19
20
    # ------------------------------------------------------------------------------------------------------------------
21 1
    def __init__(self, io, options, argument):
22
        """
23
        Object constructor.
24
25
        :param None|cleo.styles.output_style.OutputStyle io: The IO object.
26
        :param dict[str,str] options: The options of this table of contents.
27
        :param str argument: The argument of this TOC.
28
        """
29
        super().__init__(io, 'toc', options, argument)
30
31
    # ------------------------------------------------------------------------------------------------------------------
32 1
    def get_command(self):
33
        """
34
        Returns the command of this node (i.e. toc).
35
36
        :rtype: str
37
        """
38
        return 'toc'
39
40
    # ------------------------------------------------------------------------------------------------------------------
41 1
    def is_block_command(self):
42
        """
43
        Returns False.
44
45
        :rtype: bool
46
        """
47
        return False
48
49
    # ------------------------------------------------------------------------------------------------------------------
50 1
    def is_inline_command(self):
51
        """
52
        Returns True.
53
54
        :rtype: bool
55
        """
56
        return True
57
58
    # ------------------------------------------------------------------------------------------------------------------
59 1
    def generate_toc(self):
60
        """
61
        Generates the table of contents.
62
        """
63
        self._options['ids'] = []
64
65
        for key, node in node_store.nodes.items():
0 ignored issues
show
Unused Code introduced by
The variable key seems to be unused.
Loading history...
66
            if not isinstance(node, ParagraphNode) and isinstance(node, HeadingNode):
67
                node.set_toc_id()
68
69
                data = {'id': node.get_option_value('id'),
70
                        'arg': node.argument,
71
                        'level': node.get_hierarchy_level(),
72
                        'number': node.get_option_value('number')}
73
74
                self._options['ids'].append(data)
75
76
# ----------------------------------------------------------------------------------------------------------------------
77
node_store.register_inline_command('toc', TocNode)
78