Class: URITemplate::RFC6570::Expression::Named

Inherits:
URITemplate::RFC6570::Expression show all
Defined in:
lib/uri_template/rfc6570/expression/named.rb

Direct Known Subclasses

FormQuery, FormQueryContinuation, PathParameters

Constant Summary

Constants inherited from URITemplate::RFC6570::Expression

BASE_LEVEL, CHARACTER_CLASS, LIST_CONNECTOR, OPERATOR, PAIR_CONNECTOR, PAIR_IF_EMPTY, PREFIX, SEPARATOR

Constants included from Token

Token::EMPTY_ARRAY

Instance Attribute Summary

Attributes inherited from URITemplate::RFC6570::Expression

#variables

Attributes included from Expression

#variables

Instance Method Summary collapse

Methods inherited from URITemplate::RFC6570::Expression

#arity, #expand, #extract, #initialize, #level, #to_s

Methods included from ClassMethods

#generate_hash_extractor, #hash_extractor, #hash_extractors, #regex_builder

Methods included from Expression

#expression?, #literal?

Methods included from Token

#ends_with_slash?, #expand, #host?, #scheme?, #size, #starts_with_slash?, #to_s, #variables

Constructor Details

This class inherits a constructor from URITemplate::RFC6570::Expression

Instance Method Details

#expand_partial(vars) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/uri_template/rfc6570/expression/named.rb', line 65

def expand_partial( vars )
  result = []
  rest   = []
  defined = false
  @variable_specs.each do | var, expand , max_length |
    if vars.key? var
      if Utils.def? vars[var]
        if result.any? && !self.class::SEPARATOR.empty?
          result.push( Literal.new(self.class::SEPARATOR) )
        end
        one = expand_one(var, vars[var], expand, max_length)
        result.push( Literal.new(Array(one).join(self.class::SEPARATOR)) )
      end
      if expand
        rest << [var, expand, max_length]
      else
        result.push( self.class::FOLLOW_UP.new([[var,expand,max_length]]) )
      end
    else
      rest.push( [var,expand,max_length] )
    end
  end
  if result.any?
    unless self.class::PREFIX.empty? || empty_literals?( result )
      result.unshift( Literal.new(self.class::PREFIX) )
    end
    result.push( self.class::BULK_FOLLOW_UP.new(rest) ) if rest.size != 0
    return result
  else
    return [ self ]
  end
end

#to_r_sourceObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/uri_template/rfc6570/expression/named.rb', line 32

def to_r_source
  source = regex_builder
  source.group do
    source.escaped_prefix
    first = true
    @variable_specs.each do | var, expand , max_length |
      if expand
        source.capture do
          source.separated_list(first) do
            source.character_class('+')\
              .escaped_pair_connector\
              .character_class_with_comma(max_length)
          end
        end
      else
        source.group do
          source.escaped_separator unless first
          source << Regexp.escape(var)
          source.group do
            source.escaped_pair_connector
            source.capture do
              source.character_class_with_comma(max_length)
            end
            source << '|' unless self.class::PAIR_IF_EMPTY
          end
        end.length('?')
      end
      first = false
    end
  end.length('?')
  return source.join
end