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
40 41 42 43 44 45 46 47 48 |
# File 'lib/evaluation_helpers.rb', line 40 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
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/evaluation_helpers.rb', line 27 def self.equal_string_in_array(array, value, ignore_case) return false if array.nil? str_value = value.to_s str_value_downcased = nil if ignore_case return array.has_key?(value.to_s.downcase) else return array.has_key?(value.to_s) 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 |
# 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 |