Class: Mustermann::Match
- Inherits:
-
Object
- Object
- Mustermann::Match
- Defined in:
- lib/mustermann/match.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute params.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#post_match ⇒ Object
readonly
Returns the value of attribute post_match.
-
#pre_match ⇒ Object
readonly
Returns the value of attribute pre_match.
-
#string ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(pattern, string, params = {}, post_match: '', pre_match: '') ⇒ Match
constructor
A new instance of Match.
- #values_at(*keys) ⇒ Object
Constructor Details
#initialize(pattern, string, params = {}, post_match: '', pre_match: '') ⇒ Match
Returns a new instance of Match.
7 8 9 10 11 12 13 |
# File 'lib/mustermann/match.rb', line 7 def initialize(pattern, string, params = {}, post_match: '', pre_match: '') @pattern = pattern @string = string.freeze @params = params.freeze @post_match = post_match.freeze @pre_match = pre_match.freeze end |
Instance Attribute Details
#params ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute params.
5 6 7 |
# File 'lib/mustermann/match.rb', line 5 def params @params end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
5 6 7 |
# File 'lib/mustermann/match.rb', line 5 def pattern @pattern end |
#post_match ⇒ Object (readonly)
Returns the value of attribute post_match.
5 6 7 |
# File 'lib/mustermann/match.rb', line 5 def post_match @post_match end |
#pre_match ⇒ Object (readonly)
Returns the value of attribute pre_match.
5 6 7 |
# File 'lib/mustermann/match.rb', line 5 def pre_match @pre_match end |
#string ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute string.
5 6 7 |
# File 'lib/mustermann/match.rb', line 5 def string @string end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/mustermann/match.rb', line 15 def [](key) case key when String then params[key] when Symbol then params[key.to_s] else raise ArgumentError, "key must be a String or Symbol, not #{key.class}" end end |
#deconstruct_keys(keys) ⇒ Object
23 |
# File 'lib/mustermann/match.rb', line 23 def deconstruct_keys(keys) = keys.to_h { |key| [key, self[key]] } |
#eql?(other) ⇒ Boolean Also known as: ==
27 28 29 30 |
# File 'lib/mustermann/match.rb', line 27 def eql?(other) return false unless other.is_a? self.class pattern == other.pattern && string == other.string && params == other.params end |
#hash ⇒ Object
25 |
# File 'lib/mustermann/match.rb', line 25 def hash = pattern.hash ^ string.hash ^ params.hash |
#values_at(*keys) ⇒ Object
32 |
# File 'lib/mustermann/match.rb', line 32 def values_at(*keys) = keys.map { |key| self[key] } |