Completed
Push — master ( 9d3bc0...b059cb )
by Oleksandr
01:07
created

Refly.from_ini()   A

Complexity

Conditions 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
1
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import BooleanType, IntType, FloatType
7
8 1
from .interfaces import INISerializable, DefaultProvider
9 1
from .helpers import field_from_ini
10
11
12 1
@zope.interface.implementer(INISerializable)
13 1
@zope.interface.implementer(DefaultProvider)
14 1
class Refly(Model):
15 1
    is_disabled = BooleanType(
16
        default=False,
17
        required=True,
18
    )
19 1
    kia_delay = IntType(
20
        min_value=0,
21
        default=0,
22
        required=True,
23
    )
24 1
    kia_delay_multiplier = FloatType(
25
        min_value=0.0,
26
        default=0.0,
27
        required=True,
28
    )
29 1
    max_kia = IntType(
30
        min_value=-1,
31
        default=-1,
32
        required=True,
33
    )
34
35 1
    @classmethod
36
    def from_ini(cls, ini):
37
        return cls({
38
            'is_disabled': field_from_ini(
39
                cls.is_disabled, ini,
40
                'NET', 'reflyDisabled',
41
            ),
42
            'kia_delay': field_from_ini(
43
                cls.kia_delay, ini,
44
                'NET', 'reflyKIADelay',
45
            ),
46
            'kia_delay_multiplier': field_from_ini(
47
                cls.kia_delay_multiplier, ini,
48
                'NET', 'reflyKIADelayMultiplier',
49
            ),
50
            'max_kia': field_from_ini(
51
                cls.max_kia, ini,
52
                'NET', 'maxAllowedKIA',
53
            ),
54
        })
55
56 1
    @classmethod
57
    def default(cls):
58
        return cls({
59
            field_name: field.default
60
            for field_name, field in cls.fields.items()
61
        })
62