Module: EvaluationHelpers
- Defined in:
- lib/evaluation_helpers.rb
Class Method Summary collapse
- .array_contains_all(value, target) ⇒ Object
- .array_contains_any(value, target) ⇒ Object
- .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
.array_contains_all(value, target) ⇒ Object
67 68 69 70 71 |
# File 'lib/evaluation_helpers.rb', line 67 def self.array_contains_all(value, target) return false if value.nil? || target.nil? value_set = value.to_set return target.all? { |item| value_set.include?(item) || value_set.include?(item.to_i) } end |
.array_contains_any(value, target) ⇒ Object
61 62 63 64 65 |
# File 'lib/evaluation_helpers.rb', line 61 def self.array_contains_any(value, target) return false if value.nil? || target.nil? value_set = value.to_set return target.any? { |item| value_set.include?(item) || value_set.include?(item.to_i) } end |
.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
51 52 53 54 55 56 57 58 59 |
# File 'lib/evaluation_helpers.rb', line 51 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 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/evaluation_helpers.rb', line 27 def self.equal_string_in_array(array, value, ignore_case) if array.is_a?(Hash) return array.has_key?(value.to_sym) end 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 |
# 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 |