Class: Addressable::Template::MatchData
- Inherits:
-
Object
- Object
- Addressable::Template::MatchData
- 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
-
#mapping ⇒ Hash
readonly
The mapping that resulted from the match.
-
#template ⇒ Addressable::Template
readonly
The Template used for the match.
-
#uri ⇒ Addressable::URI
readonly
The URI that the Template was matched against.
Instance Method Summary collapse
-
#initialize(uri, template, mapping) ⇒ MatchData
constructor
Creates a new MatchData object.
-
#inspect ⇒ String
Returns a
String
representation of the MatchData’s state. -
#values ⇒ Array
(also: #captures)
The list of values that were captured by the Template.
-
#variables ⇒ Array
(also: #keys)
The list of variables that were present in the Template.
Constructor Details
#initialize(uri, template, mapping) ⇒ MatchData
Creates a new MatchData object. MatchData objects should never be instantiated directly.
66 67 68 69 70 |
# File 'lib/addressable/template.rb', line 66 def initialize(uri, template, mapping) # :nodoc: @uri = uri.dup.freeze @template = template @mapping = mapping.dup.freeze end |
Instance Attribute Details
#mapping ⇒ Hash (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.
88 89 90 |
# File 'lib/addressable/template.rb', line 88 def mapping @mapping end |
#template ⇒ Addressable::Template (readonly)
Returns The Template used for the match.
80 81 82 |
# File 'lib/addressable/template.rb', line 80 def template @template end |
#uri ⇒ Addressable::URI (readonly)
Returns The URI that the Template was matched against.
75 76 77 |
# File 'lib/addressable/template.rb', line 75 def uri @uri end |
Instance Method Details
#inspect ⇒ String
Returns a String
representation of the MatchData’s state.
117 118 119 120 |
# File 'lib/addressable/template.rb', line 117 def inspect sprintf("#<%s:%#0x RESULT:%s>", self.class.to_s, self.object_id, self.mapping.inspect) end |
#values ⇒ Array 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.
105 106 107 108 109 110 |
# File 'lib/addressable/template.rb', line 105 def values @values ||= self.variables.inject([]) do |accu, key| accu << self.mapping[key] accu end end |
#variables ⇒ Array 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.
95 96 97 |
# File 'lib/addressable/template.rb', line 95 def variables self.template.variables end |