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)
-
- (Hash) mapping
readonly
The mapping that resulted from the match.
-
- (Addressable::Template) template
readonly
The Template used for the match.
-
- (Addressable::URI) uri
readonly
The URI that the Template was matched against.
Instance Method Summary (collapse)
-
- (MatchData) initialize(uri, template, mapping)
constructor
Creates a new MatchData object.
-
- (String) inspect
Returns a String representation of the MatchData's state.
-
- (Array) values
(also: #captures)
The list of values that were captured by the Template.
-
- (Array) variables
(also: #keys)
The list of variables that were present in the Template.
Constructor Details
- (MatchData) initialize(uri, template, mapping)
Creates a new MatchData object. MatchData objects should never be instantiated directly.
60 61 62 63 64 |
# File 'lib/addressable/template.rb', line 60 def initialize(uri, template, mapping) @uri = uri.dup.freeze @template = template @mapping = mapping.dup.freeze end |
Instance Attribute Details
- (Hash) mapping (readonly)
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.
82 83 84 |
# File 'lib/addressable/template.rb', line 82 def mapping @mapping end |
- (Addressable::Template) template (readonly)
The Template used for the match.
74 75 76 |
# File 'lib/addressable/template.rb', line 74 def template @template end |
- (Addressable::URI) uri (readonly)
The URI that the Template was matched against.
69 70 71 |
# File 'lib/addressable/template.rb', line 69 def uri @uri end |
Instance Method Details
- (String) inspect
Returns a String representation of the MatchData's state.
111 112 113 114 |
# File 'lib/addressable/template.rb', line 111 def inspect sprintf("#<%s:%#0x RESULT:%s>", self.class.to_s, self.object_id, self.mapping.inspect) end |
- (Array) values Also known as: captures
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.
99 100 101 102 103 104 |
# File 'lib/addressable/template.rb', line 99 def values @values ||= self.variables.inject([]) do |accu, key| accu << self.mapping[key] accu end end |
- (Array) variables Also known as: keys
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.
89 90 91 |
# File 'lib/addressable/template.rb', line 89 def variables self.template.variables end |