Class: Matchi::Matcher::Base
- Inherits:
-
Object
- Object
- Matchi::Matcher::Base
- Defined in:
- lib/matchi/matcher/base.rb
Overview
Abstract matcher class.
Instance Attribute Summary collapse
-
#expected ⇒ #object_id
readonly
Any value to give to the matcher.
Class Method Summary collapse
-
.to_sym ⇒ Symbol
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 Attribute Details
#expected ⇒ #object_id (readonly)
Returns Any value to give to the matcher.
17 18 19 |
# File 'lib/matchi/matcher/base.rb', line 17 def expected @expected end |
Class Method Details
.to_sym ⇒ Symbol
Returns A symbol identifying the matcher.
8 9 10 11 12 13 14 |
# File 'lib/matchi/matcher/base.rb', line 8 def self.to_sym name.delete_prefix("Matchi::Matcher::") .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.
22 23 24 |
# File 'lib/matchi/matcher/base.rb', line 22 def inspect "#{self.class}(#{expected&.inspect})" end |
#matches? ⇒ Boolean
Abstract matcher class.
29 30 31 |
# File 'lib/matchi/matcher/base.rb', line 29 def matches? raise ::NotImplementedError, "matcher MUST respond to this method." end |
#to_s ⇒ String
Returns a string representing the matcher.
40 41 42 |
# File 'lib/matchi/matcher/base.rb', line 40 def to_s [self.class.to_sym, expected&.inspect].compact.join(" ") end |