Class: Familia::Validation::PatternExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/familia/validation/expectations.rb

Overview

Represents a pattern-based expectation

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject (readonly)

Returns the value of attribute description.



214
215
216
# File 'lib/familia/validation/expectations.rb', line 214

def description
  @description
end

#patternObject (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

Returns:

  • (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_sObject



234
235
236
# File 'lib/familia/validation/expectations.rb', line 234

def to_s
  "pattern(#{@description})"
end