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

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

Constant Summary collapse

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?, #expand_partial, #host?, #scheme?, #size, #starts_with_slash?, #to_s, #variables

Constructor Details

#initialize(index) ⇒ Splat

Returns a new instance of Splat.



102
103
104
105
# File 'lib/uri_template/colon.rb', line 102

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



100
101
102
# File 'lib/uri_template/colon.rb', line 100

def index
  @index
end

Instance Method Details

#expand(vars) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/uri_template/colon.rb', line 107

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

#to_rObject



116
117
118
# File 'lib/uri_template/colon.rb', line 116

def to_r
  return '(.+?)'
end