module Eco module API class UseCases class OozeSamples module Helpers module Shortcuts # Offers multiple ways to compare two strings def same_string?(value1, value2, exact: false) case when value1.is_a?(String) && value2.is_a?(String) if exact value1 == value2 else value1.to_s.strip.downcase == value2.to_s.strip.downcase end when value1.is_a?(Regexp) && value2.is_a?(String) value2 =~ value1 when value1.is_a?(String) && value2.is_a?(Regexp) value1 =~ value2 else value1 == value2 end end def titleize(str) return nil unless str return str if str.strip.empty? str.split(/\s+/).map do |part| part[0] = part[0].upcase part[1..-1] = part[1..-1].downcase part end.join(" ") end def normalize_string(str) return nil unless str str.gsub(/[^[:print:]]/, '') .gsub(/[[:space:]]+/, ' ') .gsub(/[[:space:]]$/, '') .gsub(/[-\u2011\u2012\u2013]/, '-').yield_self do |str| str = yield(str) if block_given? str end end def clean_question(str) return nil unless str normalize_string(str) do |str| str.gsub(/\r\n/, ' ').yield_self do |str| str = yield(str) if block_given? str end end end end end end end end end