Class: Addressable::Template::MatchData

Inherits:
Object
  • Object
show all
Defined in:
lib/addressable/template.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, template, mapping) ⇒ MatchData

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

Parameters:



102
103
104
105
106
# File 'lib/addressable/template.rb', line 102

def initialize(uri, template, mapping)
  @uri = uri.dup.freeze
  @template = template
  @mapping = mapping.dup.freeze
end

Instance Attribute Details

#mappingHash (readonly)

Returns 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.

Returns:

  • (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.



124
125
126
# File 'lib/addressable/template.rb', line 124

def mapping
  @mapping
end

#templateAddressable::Template (readonly)

Returns The Template used for the match.

Returns:



116
117
118
# File 'lib/addressable/template.rb', line 116

def template
  @template
end

#uriAddressable::URI (readonly)

Returns The URI that the Template was matched against.

Returns:



111
112
113
# File 'lib/addressable/template.rb', line 111

def uri
  @uri
end

Instance Method Details

#inspectString

Returns a String representation of the MatchData’s state.

Returns:

  • (String)

    The MatchData’s state, as a String.



153
154
155
156
# File 'lib/addressable/template.rb', line 153

def inspect
  sprintf("#<%s:%#0x RESULT:%s>",
    self.class.to_s, self.object_id, self.mapping.inspect)
end

#valuesArray Also known as: captures

Returns 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.

Returns:

  • (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.



141
142
143
144
145
146
# File 'lib/addressable/template.rb', line 141

def values
  @values ||= self.variables.inject([]) do |accu, key|
    accu << self.mapping[key]
    accu
  end
end

#variablesArray Also known as: keys

Returns 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.

Returns:

  • (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.



131
132
133
# File 'lib/addressable/template.rb', line 131

def variables
  self.template.variables
end