Sha256: 702838f7fa0110831c7e787e1fbc1b73c208512cc6f635f691c40d9d19cac233

Contents?: true

Size: 856 Bytes

Versions: 25

Compression:

Stored size: 856 Bytes

Contents

module Dugway
  class PathInterpreter
    attr_accessor :path

    def initialize(path)
      @path = path
    end

    def call
      return path unless path.is_a?(String)
      case path
      when category_artist_or_product_path
        %r{^/#{$1}/(?<#{$2}>#{permalink_regex})#{format_regex}$}
      when product_or_cart_path
        %r{^/#{$1}#{format_regex}$}
      when custom_page_path
        %r{^/(?<#{$1}>#{permalink_regex})$}
      else
        %r{^#{path}$}
      end
    end

    private

    def permalink_regex
      %r{[a-z0-9\-_]+}
    end

    def format_regex
      %r{(\.(?<format>js))?}
    end

    def category_artist_or_product_path
      %r{^/(\w+)/:(#{permalink_regex})\(\.js\)}
    end

    def product_or_cart_path
      %r{^/(\w+)\(\.js\)$}
    end

    def custom_page_path
      %r{^/:(#{permalink_regex})}
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dugway-1.0.14 lib/dugway/path_interpreter.rb
dugway-1.0.13 lib/dugway/path_interpreter.rb
dugway-1.0.12 lib/dugway/path_interpreter.rb
dugway-1.0.10 lib/dugway/path_interpreter.rb
dugway-1.0.9 lib/dugway/path_interpreter.rb
dugway-1.0.8 lib/dugway/path_interpreter.rb
dugway-1.0.7 lib/dugway/path_interpreter.rb
dugway-1.0.6 lib/dugway/path_interpreter.rb
dugway-1.0.5 lib/dugway/path_interpreter.rb
dugway-1.0.4 lib/dugway/path_interpreter.rb
dugway-1.0.3 lib/dugway/path_interpreter.rb
dugway-1.0.2 lib/dugway/path_interpreter.rb
dugway-1.0.1 lib/dugway/path_interpreter.rb
dugway-1.0.0 lib/dugway/path_interpreter.rb
dugway-0.12.3 lib/dugway/path_interpreter.rb
dugway-0.12.2 lib/dugway/path_interpreter.rb
dugway-0.12.1 lib/dugway/path_interpreter.rb
dugway-0.12.0 lib/dugway/path_interpreter.rb
dugway-0.11.4 lib/dugway/path_interpreter.rb
dugway-0.11.3 lib/dugway/path_interpreter.rb