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

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

Constructor Details

#initialize(name) ⇒ Variable

Returns a new instance of Variable.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#expand(vars) ⇒ Object



82
83
84
# File 'lib/uri_template/colon.rb', line 82

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

#to_rObject



86
87
88
# File 'lib/uri_template/colon.rb', line 86

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

#to_sObject



90
91
92
# File 'lib/uri_template/colon.rb', line 90

def to_s
  return ":#{name}"
end