Sha256: d91d930b2ca89bc45b2af5e143bfe5984de589cfebc6323b8485b6da669dea95

Contents?: true

Size: 836 Bytes

Versions: 3

Compression:

Stored size: 836 Bytes

Contents

# encoding: utf-8
module BusinessCatalyst
  module CSV

    class SEOFriendlyUrlTransformer < Transformer

      def initialize(input)
        input = input.to_s
        raise InvalidInputError, "seo_friendly_url must not be blank" if input.nil? || input.strip == ""
        raise InvalidInputError, "seo_friendly_url '#{input}' is not globally unique" unless self.class.is_globally_unique?(input)
        self.class.register_url(input)
        super(input)
      end

      def transform
        input
      end

      def self.reset_global_urls!
        @global_urls = {}
      end

      def self.global_urls
        @global_urls ||= {}
      end

      def self.register_url(url)
        global_urls[url] = true
      end

      def self.is_globally_unique?(url)
        !global_urls.fetch(url, false)
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
business_catalyst-0.1.2 lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb
business_catalyst-0.1.1 lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb
business_catalyst-0.1.0 lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb