MoleculeGland   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
dl 0
loc 38
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get_molecule_type() 0 4 2
A set_molecule_type() 0 2 1
A enable() 0 2 1
A __init__() 0 5 1
A is_enabled() 0 2 1
A appose() 0 10 3
A get_molecule() 0 2 1
A disable() 0 2 1
1
from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
2
from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
3
4
5
class MoleculeGland():
6
7
    def __init__(self, host, context):
8
        self._molecule_type = None
9
        self._host = host
10
        self._context = context
11
        self._enabled = False
12
13
    def set_molecule_type(self, molecule_type):
14
        self._molecule_type = molecule_type
15
16
    def get_molecule_type(self):
17
        if self._molecule_type is None:
18
            raise Exception("molecule_type not specified")
19
        return self._molecule_type
20
21
    def get_molecule(self):
22
        raise NotImplementedError()
23
24
    def appose(self):
25
        if not self._enabled:
26
            raise MoleculeGlandDisabled()
27
28
        try:
29
            DirectionMolecule.appose(self._context,
30
                                     self._host.get_position(),
31
                                     self.get_molecule())
32
        except BestMoleculeHere as best_molecule_here:
33
            self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
34
35
    def disable(self):
36
        self._enabled = False
37
38
    def enable(self):
39
        self._enabled = True
40
41
    def is_enabled(self):
42
        return self._enabled