Class: FormattedURL::URLSourceResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/formatted_url/url_source_resolver.rb

Overview

Finds URL source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format = :default) ⇒ URLSourceResolver

Receives the path for URL and format to work with



13
14
15
16
# File 'lib/formatted_url/url_source_resolver.rb', line 13

def initialize(path, format = :default)
  @path = path
  @format = format
end

Instance Attribute Details

#formatObject (readonly)

Working format



9
10
11
# File 'lib/formatted_url/url_source_resolver.rb', line 9

def format
  @format
end

#pathObject

The URL path



7
8
9
# File 'lib/formatted_url/url_source_resolver.rb', line 7

def path
  @path
end

Instance Method Details

#sourceObject

Defines URL source



19
20
21
22
23
24
25
26
# File 'lib/formatted_url/url_source_resolver.rb', line 19

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

#urlObject

Returns the final formatted URL



29
30
31
# File 'lib/formatted_url/url_source_resolver.rb', line 29

def url
  STRATEGIES[source].url(path, format)
end