Class: URITemplate::Colon::Token::Splat

Inherits:
Variable show all
Defined in:
lib/uri_template/colon.rb

Constant Summary

SPLAT =
'splat'.freeze

Constants included from Token

Token::EMPTY_ARRAY

Instance Attribute Summary (collapse)

Attributes inherited from Variable

#name

Attributes included from Expression

#variables

Instance Method Summary (collapse)

Methods inherited from Variable

#to_s

Methods included from Expression

#expression?, #literal?

Methods included from Token

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

Constructor Details

- (Splat) initialize(index)

A new instance of Splat



96
97
98
99
# File 'lib/uri_template/colon.rb', line 96

def initialize(index)
  @index = index
  super(SPLAT)
end

Instance Attribute Details

- (Object) index (readonly)

Returns the value of attribute index



94
95
96
# File 'lib/uri_template/colon.rb', line 94

def index
  @index
end

Instance Method Details

- (Object) expand(vars)



101
102
103
104
105
106
107
108
# File 'lib/uri_template/colon.rb', line 101

def expand(vars)
  var = vars[name]
  if Array === var
    return Utils.escape_uri(Utils.object_to_param(var[index]))
  else
    raise InvalidValue::SplatIsNotAnArray.new(name,var)
  end
end

- (Object) to_r



110
111
112
# File 'lib/uri_template/colon.rb', line 110

def to_r
  return '(.+?)'
end