lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb in eco-helpers-2.0.55 vs lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb in eco-helpers-2.0.56

- old
+ new

@@ -4,17 +4,24 @@ class OozeSamples module Helpers module Shortcuts # Offers multiple ways to compare two strings - def same_string?(value1, value2, exact: false) + def same_string?(value1, value2, exact: false, mild: 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 + v1 = value1.to_s.strip.downcase + v2 = value2.to_s.strip.downcase + + if mild + v1 = v1.gsub(/[^a-z ]+/, ' ').gsub(/\s+/, ' ').strip + v2 = v2.gsub(/[^a-z ]+/, ' ').gsub(/\s+/, ' ').strip + end + v1 == v2 end when value1.is_a?(Regexp) && value2.is_a?(String) value2 =~ value1 when value1.is_a?(String) && value2.is_a?(Regexp) value1 =~ value2 @@ -62,14 +69,34 @@ ref << "Stage" when Ecoportal::API::V2::Pages::PageStage ref << "Page (#{obj.id}) (#{object_reference(obj.current_stage)})" when Ecoportal::API::V2::Page ref << "Page" + when Ecoportal::API::V2::Page::Section + ref << "Section '#{obj.heading || "(unnamed)"}'" + when Ecoportal::API::V2::Page::Component + ref << "Component '#{obj.label || "(unnamed of type '#{obj.type}')"}' in #{object_reference(obj.section)}" + when Ecoportal::API::V2::Page::Force + ref << "Force '#{obj.name}'" + when Ecoportal::API::V2::Page::Force::Binding + ref << "Binding '#{obj.name}' in #{object_reference(obj.force)}" end ref << " '#{obj.name}'" if obj.respond_to?(:name) end end + def to_i + Float(value).to_i + end + + # https://stackoverflow.com/a/5661695/4352306 + def is_number?(value) + begin + true if Float(value) + rescue ArgumentError => e + false + end + end end end end end end