Class: Vigia::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/vigia/url.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_templateObject (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

Returns:

  • (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.expand(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 expand(parameters)
  absolute_url uri_template.expand(valid_parameters(parameters).to_hash)
end

#hostObject



32
33
34
# File 'lib/vigia/url.rb', line 32

def host
  Vigia.config.host
end