@@ -15,11 +15,16 @@ def __init__(self, rule_dict):
1515 self .value = rule_dict ["value" ]
1616
1717 def evaluate (self , obj ):
18- result = self .get_operator ()(self .get_input (obj ), self .get_value ())
18+ results = []
19+ result = self .get_operator ()(
20+ self .get_input (obj , results ),
21+ self .get_value ()
22+ )
1923 return result
2024
2125 def inputs (self , obj ):
22- inputs = self .get_input (obj )
26+ results = []
27+ inputs = self .get_input (obj , results )
2328 return inputs
2429
2530 def values (self ):
@@ -32,36 +37,24 @@ def inspect(self, obj):
3237 def get_operator (self ):
3338 return getattr (Operators , "eval_" + self .operator )
3439
35- def get_input (self , obj ):
40+ def get_input (self , obj , results ):
3641 fields = self .field .split ("." )
37- result = obj
38- steps = len (fields )
39- for i in range (steps ):
40- last_step = i == steps - 1
41- second_last_step = i == steps - 2
42- result = result .get (fields [i ])
43- if (
44- second_last_step
45- and isinstance (result , list )
46- and isinstance (result [0 ], dict )
47- ):
48- result = [x [fields [steps - 1 ]] for x in result ]
49- break
50- result = (
51- result [0 ]
52- if (
53- result is not None
54- and isinstance (result , list )
55- and not last_step
56- )
57- else result
58- )
59- if result is None :
60- break
61- if isinstance (result , list ):
62- return list (map (lambda x : self .typecast_value (x ), result ))
42+ fd_index = len (fields ) - 1
43+
44+ if isinstance (obj , list ):
45+ for i in range (len (obj )):
46+ self .get_input (obj [i ], results )
47+
48+ elif isinstance (obj , dict ):
49+ while fields [fd_index ] not in obj :
50+ fd_index -= 1
51+
52+ self .get_input (obj [fields [fd_index ]], results )
53+
6354 else :
64- return self .typecast_value (result )
55+ results .append (self .typecast_value (obj ))
56+
57+ return results
6558
6659 def get_value (self ):
6760 if isinstance (self .value , list ):
0 commit comments