Class: Wrest::UriTemplate
- Inherits:
-
Object
- Object
- Wrest::UriTemplate
- Defined in:
- lib/wrest/uri_template.rb
Instance Attribute Summary collapse
-
#uri_pattern ⇒ Object
readonly
Returns the value of attribute uri_pattern.
Instance Method Summary collapse
-
#initialize(uri_pattern) ⇒ UriTemplate
constructor
A new instance of UriTemplate.
-
#to_uri(options = {}) ⇒ Object
Builds a new Wrest::Uri from this uri template by replacing the keys in the options that match with the corressponding values.
Constructor Details
#initialize(uri_pattern) ⇒ UriTemplate
Returns a new instance of UriTemplate.
13 14 15 |
# File 'lib/wrest/uri_template.rb', line 13 def initialize(uri_pattern) @uri_pattern = uri_pattern.clone end |
Instance Attribute Details
#uri_pattern ⇒ Object (readonly)
Returns the value of attribute uri_pattern.
12 13 14 |
# File 'lib/wrest/uri_template.rb', line 12 def uri_pattern @uri_pattern end |
Instance Method Details
#to_uri(options = {}) ⇒ Object
Builds a new Wrest::Uri from this uri template by replacing the keys in the options that match with the corressponding values.
Example: template = UriTemplate.new(“localhost:3000/:resource/:id.:format”) template.to_uri(:resource => ‘shen_coins’, :id => 5, :format => :json)
> #<Wrest::Uri:0x1225514 @uri=#<URI::HTTP:0x9127d8 URL:localhost:3000/shen_coins/5.json>>
25 26 27 28 29 30 |
# File 'lib/wrest/uri_template.rb', line 25 def to_uri( = {}) .inject(uri_pattern.clone) do |uri_string, tuple| key, value = tuple uri_string.gsub(":#{key.to_s}", value.to_s) end.to_uri end |