Sha256: 9436d6a981e76774b08bec882bfaecf55d05275077bb1f077a8b25279094f1ed

Contents?: true

Size: 757 Bytes

Versions: 3

Compression:

Stored size: 757 Bytes

Contents

require File.expand_path('../strategies', __FILE__)

module FormattedURL
  # Find URL source
  class URLSourceResolver
    # The URL path
    attr_accessor :path
    # Working format
    attr_reader :format

    # Receives the +path+ for URL
    # and +format+ to work with
    def initialize(path, format = :default)
      @path = path
      @format = format
    end

    # Defines url source
    def source
      STRATEGIES.each_key do |key|
        if clean_url.include? key.to_s
          return key
        end
      end
      return :default
    end

    # Returns the final formatted URL
    def url
      STRATEGIES[source].url(path, format)
    end

    private

    # URL without "dot"
    def clean_url
      @path.gsub('.','')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formatted_url-0.0.5 lib/formatted_url/url_source_resolver.rb
formatted_url-0.0.4 lib/formatted_url/url_source_resolver.rb
formatted_url-0.0.3 lib/formatted_url/url_source_resolver.rb