From 9a7bf3bffb2a8459e66b988aaff53611723b5ab4 Mon Sep 17 00:00:00 2001 From: pepperpepperpepper Date: Sun, 29 Nov 2015 17:43:44 -0800 Subject: required=0, -e commit message for your changes. Lines starting --- ricky/param/bool.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ricky/param/bool.py (limited to 'ricky/param/bool.py') 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])) -- cgit v1.2.3-70-g09d2