Class: Matchi::Match
- Inherits:
- BasicObject
- Defined in:
- lib/matchi/match.rb
Overview
**Regular expressions** matcher.
Instance Method Summary collapse
-
#initialize(expected) ⇒ Match
constructor
Initialize the matcher with an instance of Regexp.
-
#matches? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
-
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the matcher and a value corresponding to its initialize parameters.
-
#to_s ⇒ String
Returns a string representing the matcher.
Constructor Details
#initialize(expected) ⇒ Match
Initialize the matcher with an instance of Regexp.
10 11 12 |
# File 'lib/matchi/match.rb', line 10 def initialize(expected) @expected = expected end |
Instance Method Details
#matches? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
23 24 25 |
# File 'lib/matchi/match.rb', line 23 def matches? @expected.match(yield).nil?.equal?(false) end |
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the
matcher and a value corresponding to its initialize parameters.
46 47 48 |
# File 'lib/matchi/match.rb', line 46 def to_h { Match: [@expected] } end |
#to_s ⇒ String
Returns a string representing the matcher.
34 35 36 |
# File 'lib/matchi/match.rb', line 34 def to_s "match #{@expected.inspect}" end |