Coverage for /Users/fmorton/GitHub/Birdbrain-Python-Library-2/src/birdbrain_utility.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-21 08:37 -0400

1class BirdbrainUtility: 

2 @classmethod 

3 def is_none_or_empty(self, s): 

4 if s is None or s == "": 

5 return True 

6 else: 

7 return False 

8 

9 @classmethod 

10 def bounds(self, input, input_min, input_max, pass_through_input = None): 

11 #if pass_through_input is not None and (input == pass_through_input): return int(input) 

12 

13 if int(input) < int(input_min): return int(input_min) 

14 if int(input) > int(input_max): return int(input_max) 

15 

16 return int(input) 

17 

18 @classmethod 

19 def decimal_bounds(self, input, input_min, input_max, pass_through_input = None): 

20 #if pass_through_input is not None and (input == pass_through_input): return int(input) 

21 

22 if float(input) < float(input_min): return float(input_min) 

23 if float(input) > float(input_max): return float(input_max) 

24 

25 return float(input) 

26 

27 

28 @classmethod 

29 def flatten_string(self, original_list, divider = "/"): 

30 if isinstance(original_list[0], list): original_list = original_list[0] 

31 

32 original_list = [item for item in original_list] 

33 

34 s = "" 

35 for element in list(original_list): 

36 if isinstance(element, str): 

37 s += str(element) + divider 

38 elif isinstance(element, int): 

39 s += str(element) + divider 

40 else: 

41 for sub_element in element: 

42 s += str(sub_element) + divider 

43 

44 return(s[:-1])