Sha256: c6de6e582f2b87ec38010da40d046fef48563e9f6cef11e7886ce2bb74d4603d
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 KB
Contents
require 'mustermann/ast/pattern' module Mustermann # URI template pattern implementation. # # @example # Mustermann.new('/{foo}') === '/bar' # => true # # @see Mustermann::Pattern # @see file:README.md#template Syntax description in the README # @see http://tools.ietf.org/html/rfc6570 RFC 6570 class Template < AST::Pattern on ?{ do |char| variable = proc do match = expect(/(?<name>\w+)(?:\:(?<prefix>\d{1,4})|(?<explode>\*))?/) node(:variable, match[:name], prefix: match[:prefix], explode: match[:explode]) end operator = buffer.scan(/[\+\#\.\/;\?\&\=\,\!\@\|]/) expression = node(:expression, [variable[]], operator: operator) { variable[] if scan(?,) } expression if expect(?}) end on(?}) { |c| unexpected(c) } # @!visibility private def compile(*args, **options) @split_params = {} super(*args, split_params: @split_params, **options) end # @!visibility private def map_param(key, value) return super unless variable = @split_params[key] value = value.split variable[:separator] value.map! { |e| e.sub(/\A#{key}=/, '') } if variable[:parametric] value.map! { |e| super(key, e) } end # @!visibility private def always_array?(key) @split_params.include? key end private :compile, :map_param, :always_array? end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mustermann-0.3.1 | lib/mustermann/template.rb |
mustermann-0.3.0 | lib/mustermann/template.rb |
mustermann-0.2.0 | lib/mustermann/template.rb |
mustermann-0.1.0 | lib/mustermann/template.rb |