class Addressable::Template::MatchData

This class represents the data that is extracted when a Template is matched against a URI.

Attributes

mapping[R]

@return [Hash]

The mapping that resulted from the match.
Note that this mapping does not include keys or values for
variables that appear in the Template, but are not present
in the URI.
template[R]

@return [Addressable::Template]

The Template used for the match.
uri[R]

@return [Addressable::URI]

The URI that the Template was matched against.

Public Class Methods

new(uri, template, mapping) click to toggle source

Creates a new MatchData object. MatchData objects should never be instantiated directly.

@param [Addressable::URI] uri

The URI that the template was matched against.
# File lib/addressable/template.rb, line 101
def initialize(uri, template, mapping)
  @uri = uri.dup.freeze
  @template = template
  @mapping = mapping.dup.freeze
end

Public Instance Methods

captures()
Alias for: values
inspect() click to toggle source

Returns a String representation of the MatchData's state.

@return [String] The MatchData's state, as a String.

# File lib/addressable/template.rb, line 152
def inspect
  sprintf("#<%s:%#0x RESULT:%s>",
    self.class.to_s, self.object_id, self.mapping.inspect)
end
keys()
Alias for: variables
values() click to toggle source

@return [Array]

The list of values that were captured by the Template.
Note that this list will include nils for any variables which
were in the Template, but did not appear in the URI.
# File lib/addressable/template.rb, line 140
def values
  @values ||= self.variables.inject([]) do |accu, key|
    accu << self.mapping[key]
    accu
  end
end
Also aliased as: captures
variables() click to toggle source

@return [Array]

The list of variables that were present in the Template.
Note that this list will include variables which do not appear
in the mapping because they were not present in URI.
# File lib/addressable/template.rb, line 130
def variables
  self.template.variables
end
Also aliased as: keys