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

Returns a new instance of PathRouter.



7
8
9
10
11
12
# 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
  @thumbnail_path = config.thumbnail_dir
end

Instance Method Details

#build_url(path) ⇒ Object



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

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

#capture_to_baseline(path) ⇒ Object



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

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

#hostObject Also known as: root_dir



55
56
57
# File 'lib/monet/path_router.rb', line 55

def host
  @base_url.host
end

#route_path(path) ⇒ Object

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



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

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



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

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



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

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

#to_thumbnail_path(path) ⇒ Object



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

def to_thumbnail_path(path)
  image_path = path.split(File::SEPARATOR)[-2..-1].join(File::SEPARATOR)
  File.join @thumbnail_path, image_path
end

#url_path_to_baseline(path, width) ⇒ Object



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

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

#url_to_baseline(url, width) ⇒ Object



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

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