Class: BusinessCatalyst::CSV::SEOFriendlyUrlTransformer
- Inherits:
-
Transformer
- Object
- Transformer
- BusinessCatalyst::CSV::SEOFriendlyUrlTransformer
- Defined in:
- lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb
Instance Attribute Summary
Attributes inherited from Transformer
Class Method Summary collapse
- .global_urls ⇒ Object
- .is_globally_unique?(url) ⇒ Boolean
- .register_url(url) ⇒ Object
- .reset_global_urls! ⇒ Object
Instance Method Summary collapse
-
#initialize(input) ⇒ SEOFriendlyUrlTransformer
constructor
A new instance of SEOFriendlyUrlTransformer.
- #transform ⇒ Object
Methods inherited from Transformer
Constructor Details
#initialize(input) ⇒ SEOFriendlyUrlTransformer
Returns a new instance of SEOFriendlyUrlTransformer.
7 8 9 10 11 12 13 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 7 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 |
Class Method Details
.global_urls ⇒ Object
23 24 25 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 23 def self.global_urls @global_urls ||= {} end |
.is_globally_unique?(url) ⇒ Boolean
31 32 33 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 31 def self.is_globally_unique?(url) !global_urls.fetch(url, false) end |
.register_url(url) ⇒ Object
27 28 29 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 27 def self.register_url(url) global_urls[url] = true end |
.reset_global_urls! ⇒ Object
19 20 21 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 19 def self.reset_global_urls! @global_urls = {} end |
Instance Method Details
#transform ⇒ Object
15 16 17 |
# File 'lib/business_catalyst/csv/transformers/seo_friendly_url_transformer.rb', line 15 def transform input end |