Passed
Pull Request — master (#496)
by
unknown
02:17
created

InputLimiter.transform_text()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# TODO Add docstring
2
from annif.exception import ConfigurationException
3
from . import transformer
4
5
6
class InputLimiter(transformer.IdentityTransform):
7
8
    name = 'limit'
9
10
    def __init__(self, project, input_limit):
11
        self.project = project
12
        self.input_limit = int(input_limit)
13
        self._validate_value(self.input_limit)
14
15
    def transform_text(self, text):
16
        return text[:self.input_limit]
17
18
    def _validate_value(self, input_limit):
19
        if input_limit < 0:
20
            raise ConfigurationException(
21
                'input_limit in limit_input transformer cannot be negative',
22
                project_id=self.project.project_id)
23