Class: URITemplate::Colon::Token::Variable

Inherits:
URITemplate::Colon::Token show all
Includes:
Expression
Defined in:
lib/uri_template/colon.rb

Direct Known Subclasses

Splat

Constant Summary

Constant Summary

Constants included from Token

Token::EMPTY_ARRAY

Instance Attribute Summary (collapse)

Attributes included from Expression

#variables

Instance Method Summary (collapse)

Methods included from Expression

#expression?, #literal?

Methods included from Token

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

Constructor Details

- (Variable) initialize(name)

A new instance of Variable



71
72
73
74
# File 'lib/uri_template/colon.rb', line 71

def initialize(name)
  @name = name
  @variables = [name]
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



69
70
71
# File 'lib/uri_template/colon.rb', line 69

def name
  @name
end

Instance Method Details

- (Object) expand(vars)



76
77
78
# File 'lib/uri_template/colon.rb', line 76

def expand(vars)
  return Utils.escape_url(Utils.object_to_param(vars[name]))
end

- (Object) to_r



80
81
82
# File 'lib/uri_template/colon.rb', line 80

def to_r
  return '([^/]*?)'
end

- (Object) to_s



84
85
86
# File 'lib/uri_template/colon.rb', line 84

def to_s
  return ":#{name}"
end