Module: EvaluationHelpers

Defined in:
lib/evaluation_helpers.rb

Class Method Summary collapse

Class Method Details

.compare_numbers(a, b, func) ⇒ Object



4
5
6
7
# File 'lib/evaluation_helpers.rb', line 4

def self.compare_numbers(a, b, func)
  return false unless self.is_numeric(a) && self.is_numeric(b)
  func.call(a.to_f, b.to_f) rescue false
end

.compare_times(a, b, func) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/evaluation_helpers.rb', line 16

def self.compare_times(a, b, func)
  begin
    time_1 = self.get_epoch_time(a)
    time_2 = self.get_epoch_time(b)
    func.call(time_1, time_2)
  rescue
    false
  end
end

.match_string_in_array(array, value, ignore_case, func) ⇒ Object

returns true if array has any element that evaluates to true with value using func lambda, ignoring case



10
11
12
13
14
# File 'lib/evaluation_helpers.rb', line 10

def self.match_string_in_array(array, value, ignore_case, func)
  return false unless array.is_a?(Array) && !value.nil?
  str_value = value.to_s
  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
end