statsig 1.31.1 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- # typed: true
2
1
  require 'time'
3
2
 
4
3
  module EvaluationHelpers
@@ -9,9 +8,41 @@ module EvaluationHelpers
9
8
 
10
9
  # returns true if array has any element that evaluates to true with value using func lambda, ignoring case
11
10
  def self.match_string_in_array(array, value, ignore_case, func)
12
- return false unless array.is_a?(Array) && !value.nil?
13
11
  str_value = value.to_s
14
- array.any?{ |s| !s.nil? && ((ignore_case && func.call(str_value.downcase, s.to_s.downcase)) || func.call(str_value, s.to_s)) } rescue false
12
+ str_value_downcased = nil
13
+
14
+ return false if array.nil?
15
+
16
+ return array.any? do |item|
17
+ next false if item.nil?
18
+ item_str = item.to_s
19
+
20
+ return true if func.call(str_value, item_str)
21
+ next false unless ignore_case
22
+
23
+ str_value_downcased ||= str_value.downcase
24
+ func.call(str_value_downcased, item_str.downcase)
25
+ end
26
+ end
27
+
28
+ def self.equal_string_in_array(array, value, ignore_case)
29
+ str_value = value.to_s
30
+ str_value_downcased = nil
31
+
32
+ return false if array.nil?
33
+
34
+ return array.any? do |item|
35
+ next false if item.nil?
36
+ item_str = item.to_s
37
+
38
+ next false unless item_str.length == str_value.length
39
+
40
+ return true if item_str == str_value
41
+ next false unless ignore_case
42
+
43
+ str_value_downcased ||= str_value.downcase
44
+ item_str.downcase == str_value_downcased
45
+ end
15
46
  end
16
47
 
17
48
  def self.compare_times(a, b, func)
@@ -27,6 +58,7 @@ module EvaluationHelpers
27
58
  private
28
59
 
29
60
  def self.is_numeric(v)
61
+ return true if v.is_a?(Numeric)
30
62
  !(v.to_s =~ /\A[-+]?\d*\.?\d+\z/).nil?
31
63
  end
32
64