Class: Familia::Validation::PatternExpectation
- Inherits:
-
Object
- Object
- Familia::Validation::PatternExpectation
- Defined in:
- lib/familia/validation/expectations.rb
Overview
Represents a pattern-based expectation
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, description = nil) ⇒ PatternExpectation
constructor
A new instance of PatternExpectation.
-
#matches?(recorded_command) ⇒ Boolean
-
#to_s ⇒ Object
Constructor Details
#initialize(pattern, description = nil) ⇒ PatternExpectation
Returns a new instance of PatternExpectation.
216 217 218 219 |
# File 'lib/familia/validation/expectations.rb', line 216 def initialize(pattern, description = nil) @pattern = pattern @description = description || pattern.to_s end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
214 215 216 |
# File 'lib/familia/validation/expectations.rb', line 214 def description @description end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
214 215 216 |
# File 'lib/familia/validation/expectations.rb', line 214 def pattern @pattern end |
Instance Method Details
#matches?(recorded_command) ⇒ Boolean
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/familia/validation/expectations.rb', line 221 def matches?(recorded_command) case @pattern when Regexp @pattern.match?(recorded_command.to_s) when String recorded_command.to_s.include?(@pattern) when Proc @pattern.call(recorded_command) else false end end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/familia/validation/expectations.rb', line 234 def to_s "pattern(#{@description})" end |