Sha256: 8e3e8ec83e6f31df6359d0252a1572c695e64034b50c820e48d6730aa7d1cc4d

Contents?: true

Size: 1.22 KB

Versions: 36

Compression:

Stored size: 1.22 KB

Contents

module Ecoportal
  module API
    module Common
      module Content
        module ModelHelpers

          private

          # Offers multiple ways to compare two strings
          # Offers multiple ways to compare two strings
          def same_string?(value1, value2, exact: false, mild: false)
            case
            when value1.is_a?(String) && value2.is_a?(String)
              if exact
                value1 == value2
              else
                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
            else
              value1 == value2
            end
          end

          def hash_except(hash, *keys)
            keys.each {|key| hash.delete(key)}
            hash
          end

        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.12 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.11 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.10 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.9 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.8 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.7 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.6 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.5 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.4 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.3 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.2 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.1 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-2.0.0 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.8 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.7 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.6 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.5 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.4 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.3 lib/ecoportal/api/common/content/model_helpers.rb
ecoportal-api-v2-1.1.2 lib/ecoportal/api/common/content/model_helpers.rb