Class: Vigia::Url
- Inherits:
-
Object
- Object
- Vigia::Url
- Defined in:
- lib/vigia/url.rb
Instance Attribute Summary collapse
-
#uri_template ⇒ Object
readonly
Returns the value of attribute uri_template.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_url(path) ⇒ Object
- #expand(parameters) ⇒ Object
- #host ⇒ Object
-
#initialize(template) ⇒ Url
constructor
A new instance of Url.
Constructor Details
#initialize(template) ⇒ Url
Returns a new instance of Url.
20 21 22 |
# File 'lib/vigia/url.rb', line 20 def initialize(template) @uri_template = Addressable::Template.new(template) end |
Instance Attribute Details
#uri_template ⇒ Object (readonly)
Returns the value of attribute uri_template.
18 19 20 |
# File 'lib/vigia/url.rb', line 18 def uri_template @uri_template end |
Class Method Details
.template_defines_url?(template, url) ⇒ Boolean
9 10 11 12 13 14 15 |
# File 'lib/vigia/url.rb', line 9 def template_defines_url?(template, url) url_object = Addressable::URI.parse(url) template_object = Addressable::Template.new(template) url_parameters = template_object.extract(url_object) || {} # recreate url and see if matches template_object.(url_parameters) == url_object end |
Instance Method Details
#absolute_url(path) ⇒ Object
28 29 30 |
# File 'lib/vigia/url.rb', line 28 def absolute_url path URI.join(host, path).to_s end |
#expand(parameters) ⇒ Object
24 25 26 |
# File 'lib/vigia/url.rb', line 24 def (parameters) absolute_url uri_template.(valid_parameters(parameters).to_hash) end |