Class: Helpers::Url
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #full(new_extension = nil) ⇒ Object
-
#initialize(url_path, prefix = nil) ⇒ Url
constructor
Create a new Url object.
-
#join(prefix, path, suffix = nil) ⇒ Object
Join a set of paths together.
- #to_s ⇒ Object
Constructor Details
#initialize(url_path, prefix = nil) ⇒ Url
Create a new Url object.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/helpers/url.rb', line 12 def initialize(url_path, prefix=nil) if url_path.is_a?(Path) @path = url_path elsif url_path.is_a?(String) @path = Path.new(url_path) elsif url_path.is_a?(Url) @path = url_path.path else raise "Url must be initialized with a String, Url, or Path instance." end @prefix = prefix end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
30 31 32 |
# File 'lib/helpers/url.rb', line 30 def path @path end |
Instance Method Details
#+(other) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/helpers/url.rb', line 32 def + (other) if other.is_a?(String) Url.new(@path + other, prefix=@prefix) elsif other.is_a?(Url) Url.new(@path + other.path.relative, prefix=@prefix) elsif other.is_a?(Path) Url.new(@path + other.relative_path, prefix=@prefix) else raise "Url + accepts String, Path, and Url instances." end end |
#full(new_extension = nil) ⇒ Object
52 53 54 |
# File 'lib/helpers/url.rb', line 52 def full(new_extension=nil) new_extension.nil? ? join(@prefix, @path) : join(@prefix, @path.with_extension(new_extension)) end |
#join(prefix, path, suffix = nil) ⇒ Object
Join a set of paths together
57 58 59 60 |
# File 'lib/helpers/url.rb', line 57 def join(prefix, path, suffix=nil) root = prefix.nil? ? path.relative : prefix + "/" + path.relative suffix.nil? ? root : root + "/" + suffix end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/helpers/url.rb', line 48 def to_s full end |