Module: EvaluationHelpers
- Defined in:
- lib/evaluation_helpers.rb
Class Method Summary collapse
- .compare_numbers(a, b, func) ⇒ Object
- .compare_times(a, b, func) ⇒ Object
-
.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.
Class Method Details
.compare_numbers(a, b, func) ⇒ Object
5 6 7 8 |
# File 'lib/evaluation_helpers.rb', line 5 def self.compare_numbers(a, b, func) return false unless is_numeric(a) && is_numeric(b) func.call(a.to_f, b.to_f) rescue false end |
.compare_times(a, b, func) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/evaluation_helpers.rb', line 17 def self.compare_times(a, b, func) begin time_1 = get_epoch_time(a) time_2 = 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
11 12 13 14 15 |
# File 'lib/evaluation_helpers.rb', line 11 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 |