summaryrefslogtreecommitdiff
path: root/support/optexcount/src/header.py
blob: e6e4b2e0ce3218635f234f9f41f38ebe15ffa2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Header:
    """
    Class represents header (all types - title, chapter, section, subsection) and its word counts
    """
    def __init__(self, header_type):
        self.type = header_type  # title, chapter, section, subsection
        self.words = []
        self.header_count = 0
        self.text_count = 0
        self.caption_count = 0

    def add_header_word(self, word):
        self.words.append(word)
        self.header_count += 1

    def add_text_word(self):
        self.text_count += 1

    def add_caption_word(self):
        self.caption_count += 1

    def __str__(self):
        result = "  " + self.type + " ("
        result += str(self.header_count) + " + " + str(self.text_count) + " + " + str(self.caption_count) + ")"
        for word in self.words:
            result += " " + word
        return result