class Addressable::Template

def partial_expand(mapping, processor=nil)

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

Parameters:
  • processor (#validate, #transform) --
  • mapping (Hash) -- The mapping that corresponds to the pattern.
def partial_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, true
        )
      end
    else
      varname, _, vardefault = capture.scan(/^\{(.+?)(=(.*))?\}$/)[0]
      if transformed_mapping[varname]
        transformed_mapping[varname]
      elsif vardefault
        "{#{varname}=#{vardefault}}"
      else
        "{#{varname}}"
      end
    end
  end
  return Addressable::Template.new(result)
end