Class: Reynard::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/reynard/template.rb

Overview

Basic implementation of URI templates.

See: RFC6570

Constant Summary collapse

VARIABLE_RE =
/\{([^}]+)\}/

Instance Method Summary collapse

Constructor Details

#initialize(template, params) ⇒ Template

Returns a new instance of Template.



10
11
12
13
# File 'lib/reynard/template.rb', line 10

def initialize(template, params)
  @template = template
  @params = params
end

Instance Method Details

#resultObject



15
16
17
18
19
# File 'lib/reynard/template.rb', line 15

def result
  @template.gsub(VARIABLE_RE) do
    Rack::Utils.escape_path(@params.fetch(Regexp.last_match(1)).to_s)
  end
end