Module: EvaluationHelpers
- Defined in:
- lib/evaluation_helpers.rb
Class Method Summary collapse
- .compare_numbers(a, b, func) ⇒ Object
- .compare_times(a, b, func) ⇒ Object
- .equal_string_in_array(array, value, ignore_case) ⇒ 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
4 5 6 7 |
# File 'lib/evaluation_helpers.rb', line 4 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/evaluation_helpers.rb', line 48 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 |
.equal_string_in_array(array, value, ignore_case) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/evaluation_helpers.rb', line 28 def self.equal_string_in_array(array, value, ignore_case) str_value = value.to_s str_value_downcased = nil return false if array.nil? return array.any? do |item| next false if item.nil? item_str = item.to_s next false unless item_str.length == str_value.length return true if item_str == str_value next false unless ignore_case str_value_downcased ||= str_value.downcase item_str.downcase == str_value_downcased 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 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/evaluation_helpers.rb', line 10 def self.match_string_in_array(array, value, ignore_case, func) str_value = value.to_s str_value_downcased = nil return false if array.nil? return array.any? do |item| next false if item.nil? item_str = item.to_s return true if func.call(str_value, item_str) next false unless ignore_case str_value_downcased ||= str_value.downcase func.call(str_value_downcased, item_str.downcase) end end |