Class: Monet::PathRouter

Inherits:
Object
  • Object
show all
Includes:
URLHelpers
Defined in:
lib/monet/path_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ PathRouter



7
8
9
10
11
# File 'lib/monet/path_router.rb', line 7

def initialize(config)
  @base_url = parse_uri(config.base_url)
  @capture_path = config.capture_dir
  @baseline_path = config.baseline_dir
end

Instance Method Details

#build_url(path) ⇒ Object



13
14
15
# File 'lib/monet/path_router.rb', line 13

def build_url(path)
  "#{@base_url}#{path}"
end

#capture_to_baseline(path) ⇒ Object



37
38
39
# File 'lib/monet/path_router.rb', line 37

def capture_to_baseline(path)
  path.gsub(@capture_path, @baseline_path)
end

#hostObject Also known as: root_dir



49
50
51
# File 'lib/monet/path_router.rb', line 49

def host
  @base_url.host
end

#route_path(path) ⇒ Object

takes a path, returns the URL used to generate the image



42
43
44
45
46
47
# File 'lib/monet/path_router.rb', line 42

def route_path(path)
  url = path.split("/").last
  path = url.split('|')[1..-1].join("/").gsub(/-\d+\.png/, "")

  "#{@base_url}/#{path}"
end

#route_url(url, width = "*") ⇒ Object

takes a url, gives the image path



18
19
20
21
# File 'lib/monet/path_router.rb', line 18

def route_url(url, width="*")
  uri = parse_uri(url)
  route_url_path(uri.path, width)
end

#route_url_path(path, width = "*") ⇒ Object

takes a url path, gives the image path



24
25
26
# File 'lib/monet/path_router.rb', line 24

def route_url_path(path, width="*")
  image_name(@capture_path, path, width)
end

#url_path_to_baseline(path, width) ⇒ Object



33
34
35
# File 'lib/monet/path_router.rb', line 33

def url_path_to_baseline(path, width)
  image_name(@baseline_path, path, width)
end

#url_to_baseline(url, width) ⇒ Object



28
29
30
31
# File 'lib/monet/path_router.rb', line 28

def url_to_baseline(url, width)
  uri = parse_uri(url)
  url_path_to_baseline(uri.path, width)
end