/
style.rb
40 lines (33 loc) · 843 Bytes
/
style.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Style
attr_reader :url_to_styles, :name, :field_name, :file_path
def initialize full_url
matches = full_url.match(STYLE_RE)
@url_to_styles = matches[1]
@name = matches[2]
@field_name = matches[5]
@file_path = matches[3]
end
def name=(name)
@name = name
end
def url
"#{@url_to_styles}#{@name}/#{@file_path}"
end
def mixmash style, url
mixed = Style.new(url)
mixed.name = style
mixed.url
end
def nested
Style.new(nested_url)
end
private
# http://dic.audrey/sites/default/files/styles/large/public/field/image/news.jpg
# http://dic.audrey/sites/default/files/styles/large/public/styles/large/public/field/image/news.jpg
def nested_path
"#{@name}/public/styles/#{@name}/#{@file_path}"
end
def nested_url
"#{@url_to_styles}#{nested_path}"
end
end