Class: Matchi::Matcher::Base
- Inherits:
-
Object
- Object
- Matchi::Matcher::Base
- Defined in:
- lib/matchi/matcher/base.rb
Overview
Abstract matcher class.
Direct Known Subclasses
BeAnInstanceOf, BeFalse, BeNil, BeTrue, Eql, Equal, Match, RaiseException
Instance Attribute Summary collapse
-
#expected ⇒ #object_id
readonly
Any value to give to the matcher.
Class Method Summary collapse
-
.to_sym ⇒ Symbol
Returns a symbol identifying the matcher.
Instance Method Summary collapse
-
#inspect ⇒ String
A string containing a human-readable representation of the matcher.
-
#matches? ⇒ Boolean
Abstract matcher class.
-
#to_s ⇒ String
Returns a string representing the matcher instance.
Instance Attribute Details
#expected ⇒ #object_id (readonly)
Returns Any value to give to the matcher.
24 25 26 |
# File 'lib/matchi/matcher/base.rb', line 24 def expected @expected end |
Class Method Details
.to_sym ⇒ Symbol
Returns a symbol identifying the matcher.
14 15 16 17 18 19 20 21 |
# File 'lib/matchi/matcher/base.rb', line 14 def self.to_sym name.split("::") .fetch(-1) .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase .to_sym end |
Instance Method Details
#inspect ⇒ String
A string containing a human-readable representation of the matcher.
33 34 35 |
# File 'lib/matchi/matcher/base.rb', line 33 def inspect "#{self.class}(#{expected&.inspect})" end |
#matches? ⇒ Boolean
Abstract matcher class.
47 48 49 |
# File 'lib/matchi/matcher/base.rb', line 47 def matches? raise ::NotImplementedError, "matcher MUST respond to this method." end |
#to_s ⇒ String
Returns a string representing the matcher instance.
58 59 60 |
# File 'lib/matchi/matcher/base.rb', line 58 def to_s [self.class.to_sym, expected&.inspect].compact.join(" ") end |