Class: OASRequest::PathTemplate
- Inherits:
-
Object
- Object
- OASRequest::PathTemplate
- Defined in:
- lib/oas_request/path_template.rb
Class Method Summary collapse
Class Method Details
.template(url, params) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/oas_request/path_template.rb', line 2 def self.template(url, params) params_symbol = params.transform_keys(&:to_s) params_in_url = url.scan(/\{(?<param>[^\/]+)\}/) params_in_url.each do |params_group| params_group.each do |param| next unless params_symbol.key? param r = Regexp.new "{#{param}}" url = url.gsub(r, params_symbol.fetch(param).to_s) end end url.gsub("{", "%7B").gsub("}", "%7D") end |