class Addressable::Template

def expand(mapping, processor=nil)

Returns:
  • (Addressable::URI) - The expanded URI template.

Parameters:
  • processor (#validate, #transform) --
  • mapping (Hash) -- The mapping that corresponds to the pattern.
def expand(mapping, processor=nil)
  result = self.pattern.dup
  transformed_mapping = transform_mapping(mapping, processor)
  result.gsub!(
    /#{OPERATOR_EXPANSION}|#{VARIABLE_EXPANSION}/
  ) do |capture|
    if capture =~ OPERATOR_EXPANSION
      operator, argument, variables, default_mapping =
        parse_template_expansion(capture, transformed_mapping)
      expand_method = "expand_#{operator}_operator"
      if ([expand_method, expand_method.to_sym] & private_methods).empty?
        raise InvalidTemplateOperatorError,
          "Invalid template operator: #{operator}"
      else
        send(expand_method.to_sym, argument, variables, default_mapping)
      end
    else
      varname, _, vardefault = capture.scan(/^\{(.+?)(=(.*))?\}$/)[0]
      transformed_mapping[varname] || vardefault
    end
  end
  return Addressable::URI.parse(result)
end