diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:43:44 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:43:44 -0800 |
| commit | 9a7bf3bffb2a8459e66b988aaff53611723b5ab4 (patch) | |
| tree | cc4ef0de15e22f5c6e5f8d2ecf16db0486d7a8ff /ricky/param/bool.py | |
| parent | 10a619b2c7227b2ad214fbb985141b884fbe87fb (diff) | |
required=0, -e commit message for your changes. Lines starting
Diffstat (limited to 'ricky/param/bool.py')
| -rw-r--r-- | ricky/param/bool.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ricky/param/bool.py b/ricky/param/bool.py new file mode 100644 index 0000000..b95f1f1 --- /dev/null +++ b/ricky/param/bool.py @@ -0,0 +1,35 @@ +from ricky.param import Param +import re +import random + + +class Bool(Param): + def __init__(self, **kwargs): + super(Bool, self).__init__(**kwargs) + + def value_get(self): + return super(Bool, self).value_get() + + def value_set(self, value): + value = self._bool_correct(value) + super(Bool, self).value_set(value) + + value = property(value_get, value_set) + + def _bool_correct(self, value): + if any in [ + re.match(r'(true|1)', value, re.IGNORECASE), + value == 1, + ]: + value = True + elif any in [ + re.match(r'(false|0)', value, re.IGNORECASE), + value == 0, + ]: + value = False + else: + raise ValueError("Bad Value for Bool %s" % value) + return value + + def randomize(self): + self.value_set(random.choice([True, False])) |
