summaryrefslogtreecommitdiff
path: root/ricky/param
diff options
context:
space:
mode:
Diffstat (limited to 'ricky/param')
-rw-r--r--ricky/param/color.py4
-rw-r--r--ricky/param/multiselect.py6
-rw-r--r--ricky/param/numberrange.py8
-rw-r--r--ricky/param/param.py22
-rw-r--r--ricky/param/selection.py (renamed from ricky/param/option.py)4
-rw-r--r--ricky/param/selections.py (renamed from ricky/param/options.py)8
6 files changed, 26 insertions, 26 deletions
diff --git a/ricky/param/color.py b/ricky/param/color.py
index ecec79c..4d9f4d5 100644
--- a/ricky/param/color.py
+++ b/ricky/param/color.py
@@ -23,11 +23,11 @@ class Color(Param):
def randomize(self):
weights_total = sum(
- map(lambda x: x["weight"], self.options())
+ map(lambda x: x["weight"], self.selections())
) + (255 * 255 * 255)
choice = random.randint(0, weights_total)
position = 0
- for elem in self.options():
+ for elem in self.selections():
position += elem["weight"]
if position >= choice:
self.value = elem["value"]
diff --git a/ricky/param/multiselect.py b/ricky/param/multiselect.py
index 68df161..21eca78 100644
--- a/ricky/param/multiselect.py
+++ b/ricky/param/multiselect.py
@@ -10,7 +10,7 @@ class MultiSelect(Param):
return super(MultiSelect, self).value_get()
def value_set(self, value):
- if not any([value == i['value'] for i in self._options]) and \
+ if not any([value == i['value'] for i in self._selections]) and \
value is not None:
raise ValueError
super(MultiSelect, self).value_set(value)
@@ -18,10 +18,10 @@ class MultiSelect(Param):
value = property(value_get, value_set)
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.options()))
+ weights_total = sum(map(lambda x: x["weight"], self.selections()))
choice = random.randint(0, weights_total)
position = 0
- for elem in self.options():
+ for elem in self.selections():
position += elem["weight"]
if position >= choice:
self.value = elem["value"]
diff --git a/ricky/param/numberrange.py b/ricky/param/numberrange.py
index 8fe517b..626d128 100644
--- a/ricky/param/numberrange.py
+++ b/ricky/param/numberrange.py
@@ -10,18 +10,18 @@ class NumberRange(Param):
def randomize(self):
weights_total = sum(
- map(lambda x: x["weight"], self.options())
+ map(lambda x: x["weight"], self.selections())
)# + self.range_max - self.range_min
if weights_total < 100:
weights_total = 100;
choice = random.randint(0, weights_total)
import sys
- sys.stderr.write("choosing %s: random_int: %s, options: %s\n" % (
+ sys.stderr.write("choosing %s: random_int: %s, selections: %s\n" % (
self.name,
choice,
- self.options()))
+ self.selections()))
position = 0
- for elem in self.options():
+ for elem in self.selections():
position += elem["weight"]
if position >= choice:
self.value = elem["value"]
diff --git a/ricky/param/param.py b/ricky/param/param.py
index 57c801a..6f7e2a7 100644
--- a/ricky/param/param.py
+++ b/ricky/param/param.py
@@ -15,19 +15,19 @@ class Param(object):
self.is_ready = 0
self._value = value
self.set_by_user = set_by_user
- self._options = kwargs.get('options') or []
- if len(self._options):
- self._validate_options()
+ self._selections = kwargs.get('selections') or []
+ if len(self._selections):
+ self._validate_selections()
"""default value is the option with the heaviest weight"""
self.default(self._choose_heaviest())
- def options(self):
- return self._options
+ def selections(self):
+ return self._selections
- def _validate_options(self):
+ def _validate_selections(self):
try:
- int(self._options[0]['weight'])
- self._options[0]['value']
+ int(self._selections[0]['weight'])
+ self._selections[0]['value']
except Exception:
raise ValueError('Unable to validate %s\n:' % self.name)
@@ -72,13 +72,13 @@ class Param(object):
heaviest_idx = 0
heaviest_weight = 0
idx = 0
- if (len(self.options())):
- for elem in self.options():
+ if (len(self.selections())):
+ for elem in self.selections():
if elem["weight"] > heaviest_weight:
heaviest_weight = elem["weight"]
heaviest_idx = idx
idx += 1
- return self.options()[heaviest_idx]["value"]
+ return self.selections()[heaviest_idx]["value"]
else:
self.randomize()
diff --git a/ricky/param/option.py b/ricky/param/selection.py
index 89bd5db..93a8388 100644
--- a/ricky/param/option.py
+++ b/ricky/param/selection.py
@@ -1,6 +1,6 @@
-class Option(dict):
+class Selection(dict):
def __init__(self, **kwargs):
- super(Option, self).__init__(**kwargs)
+ super(Selection, self).__init__(**kwargs)
self.value = kwargs["value"]
self.weight = kwargs["weight"]
def __getattr__(self, attr):
diff --git a/ricky/param/options.py b/ricky/param/selections.py
index 2a21cce..303c92e 100644
--- a/ricky/param/options.py
+++ b/ricky/param/selections.py
@@ -1,6 +1,6 @@
-from ricky.param.option import Option
+from ricky.param.option import Selection
import sys
-class Options:
+class Selections:
def __init__(self, *args):
self._values = args
def __iter__(self):
@@ -17,5 +17,5 @@ class Options:
return i
@classmethod
def from_dict(cls, *args):
- options = map(lambda x: Option(**x), args);
- return cls(*options);
+ selections = map(lambda x: Selection(**x), args);
+ return cls(*selections);