Passed
Pull Request — master (#291)
by Marek
01:53
created

osci.dialog.Filter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Filter.AND() 0 5 3
A Filter.OR() 0 5 3
A Filter.add() 0 2 1
A Filter.__init__() 0 2 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A false() 0 2 1
A true() 0 2 1
1
#
2
#  Copyright 2001 - 2020 Ludek Smid [http://www.ospace.net/]
3
#
4
#  This file is part of Outer Space.
5
#
6
#  Outer Space is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
8
#  the Free Software Foundation; either version 2 of the License, or
9
#  (at your option) any later version.
10
#
11
#  Outer Space is distributed in the hope that it will be useful,
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#  GNU General Public License for more details.
15
#
16
#  You should have received a copy of the GNU General Public License
17
#  along with Outer Space; if not, write to the Free Software
18
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
#
20
21
22
def false(value):
23
    return False
24
25
26
def true(value):
27
    return True
28
29
30
class Filter(object):
31
    def __init__(self):
32
        self.functions = []
33
34
    def add(self, func):
35
        self.functions.append(func)
36
37
    def OR(self, value):
38
        for func in self.functions:
39
            if func(value):
40
                return True
41
        return False
42
43
    def AND(self, value):
44
        for func in self.functions:
45
            if not func(value):
46
                return False
47
        return True
48