Module: EvaluationHelpers
- Defined in:
- lib/evaluation_helpers.rb
Class Method Summary collapse
-
.array_contains(array, value, ignore_case) ⇒ Object
returns true if array contains value, ignoring case when comparing strings.
- .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
.array_contains(array, value, ignore_case) ⇒ Object
returns true if array contains value, ignoring case when comparing strings
10 11 12 13 14 15 16 |
# File 'lib/evaluation_helpers.rb', line 10 def self.array_contains(array, value, ignore_case) return false unless array.is_a?(Array) && !value.nil? if value.is_a?(String) && match_string_in_array(array, value, ignore_case, ->(a, b) { a == b }) return true end return array.include?(value) 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 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
24 25 26 27 28 29 30 31 32 |
# File 'lib/evaluation_helpers.rb', line 24 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
19 20 21 22 |
# File 'lib/evaluation_helpers.rb', line 19 def self.match_string_in_array(array, value, ignore_case, func) return false unless array.is_a?(Array) && value.is_a?(String) array.any?{ |s| s.is_a?(String) && ((ignore_case && func.call(value.downcase, s.downcase)) || func.call(value, s)) } rescue false end |