Completed
Push — master ( a0f2bc...6d93c3 )
by Wojtek
8s
created

grortir.main.model.processes.factories.CallsProcessFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 33
ccs 17
cts 17
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 6 1
A _create_stages() 0 4 2
A construct_process() 0 5 1
A _update_structure() 0 6 2
1
"""Contains factory class of process with calls stages."""
2
3 1
from grortir.main.model.processes.calls_process import CallsProcess
4 1
from grortir.main.model.stages.calls_stage import CallsStage
5
6
7 1
class CallsProcessFactory:
8
    """Class which produce process with the same type of stages.
9
10
    Attributes:
11
        structure_type (str): represent type of structure
12
        how_many_nodes (int): how many nodes should be in generated process
13
        process (CallsProcess): process which will be incrementally build
14
    """
15
16 1
    def __init__(self, structure_type, how_many_nodes):
17
        """Constructor."""
18 1
        self._stages_to_add = []
19 1
        self.structure_type = structure_type
20 1
        self.how_many_nodes = how_many_nodes
21 1
        self.process = CallsProcess()
22
23 1
    def _update_structure(self):
24
        """Update structure of process."""
25 1
        if self.structure_type == "linear":
26 1
            self.process.add_path(self._stages_to_add)
27
        else:
28 1
            raise NotImplementedError()
29
30 1
    def _create_stages(self):
31
        """Create stages which will be injected to process."""
32 1
        for i in range(self.how_many_nodes):
33 1
            self._stages_to_add += [CallsStage(str(i))]
34
35 1
    def construct_process(self):
36
        """Construct process."""
37 1
        self._create_stages()
38 1
        self._update_structure()
39
        return self.process
40