From 3b9264794a4d28cdad56633f52a8f6fcd1ed7a28 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Wed, 30 May 2018 09:30:13 -0700 Subject: [PATCH 1/4] Rename base to bases --- truths/truths.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/truths/truths.py b/truths/truths.py index e55ba88..43f4058 100644 --- a/truths/truths.py +++ b/truths/truths.py @@ -25,25 +25,25 @@ class Gob(object): class Truths(object): - def __init__(self, base=None, phrases=None, ints=True): - if not base: + def __init__(self, bases=None, phrases=None, ints=True): + if not bases: raise Exception('Base items are required') - self.base = base + self.bases = bases self.phrases = phrases or [] self.ints = ints # generate the sets of booleans for the bases self.base_conditions = list(itertools.product([False, True], - repeat=len(base))) + repeat=len(bases))) # regex to match whole words defined in self.bases # used to add object context to variables in self.phrases - self.p = re.compile(r'(? Date: Wed, 30 May 2018 09:57:46 -0700 Subject: [PATCH 2/4] Replace gob with a dict --- truths/truths.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/truths/truths.py b/truths/truths.py index 43f4058..d7c2420 100644 --- a/truths/truths.py +++ b/truths/truths.py @@ -20,10 +20,6 @@ import re -class Gob(object): - pass - - class Truths(object): def __init__(self, bases=None, phrases=None, ints=True): if not bases: @@ -41,20 +37,16 @@ def __init__(self, bases=None, phrases=None, ints=True): self.p = re.compile(r'(? Date: Wed, 30 May 2018 10:06:01 -0700 Subject: [PATCH 3/4] Replace bases in phrases with literal bool value --- truths/truths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truths/truths.py b/truths/truths.py index d7c2420..6115c48 100644 --- a/truths/truths.py +++ b/truths/truths.py @@ -42,7 +42,7 @@ def calculate(self, *args): # each phrase eval_phrases = [] for item in self.phrases: - item = self.p.sub(r"bools['\1']", item) + item = self.p.sub(lambda match: str(bools[match.group(0)]), item) eval_phrases.append(eval(item)) # add the bases and evaluated phrases to create a single row From f27a9f5072c3a05a6f76ab728050ae57d21acbe5 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Wed, 30 May 2018 16:06:43 -0700 Subject: [PATCH 4/4] Rename item to phrase in phrases loop --- truths/truths.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/truths/truths.py b/truths/truths.py index 6115c48..029836a 100644 --- a/truths/truths.py +++ b/truths/truths.py @@ -41,9 +41,9 @@ def calculate(self, *args): # substitute bases with boolean values in self.phrases then evaluate # each phrase eval_phrases = [] - for item in self.phrases: - item = self.p.sub(lambda match: str(bools[match.group(0)]), item) - eval_phrases.append(eval(item)) + for phrase in self.phrases: + phrase = self.p.sub(lambda match: str(bools[match.group(0)]), phrase) + eval_phrases.append(eval(phrase)) # add the bases and evaluated phrases to create a single row row = [val for key, val in bools.items()] + eval_phrases