module Eco::API::UseCases::OozeSamples::Helpers::Shortcuts
Public Instance Methods
clean_question(str) { |str| ... }
click to toggle source
# File lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb, line 47 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
normalize_string(str) { |str| ... }
click to toggle source
# File lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb, line 36 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
object_reference(obj)
click to toggle source
# File lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb, line 57 def object_reference(obj) return "No reference" unless obj "".tap do |ref| case obj when Ecoportal::API::V2::Page::Stage ref << "Stage" when Ecoportal::API::V2::Pages::PageStage ref << "Page (#{obj.id}) (#{object_reference(obj.current_stage)})" when Ecoportal::API::V2::Page ref << "Page" end ref << " '#{obj.name}'" if obj.respond_to?(:name) end end
same_string?(value1, value2, exact: false)
click to toggle source
Offers multiple ways to compare two strings
# File lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb, line 9 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
titleize(str)
click to toggle source
# File lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb, line 26 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