Class: Oval::Match

Inherits:
Base
  • Object
show all
Defined in:
lib/oval/match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

ensure_equal, it_should, validate

Constructor Details

#initialize(re) ⇒ Match

Returns a new instance of Match.



21
22
23
# File 'lib/oval/match.rb', line 21

def initialize(re)
  self.re = re
end

Instance Attribute Details

#reObject

Returns the value of attribute re.



25
26
27
# File 'lib/oval/match.rb', line 25

def re
  @re
end

Class Method Details

.[](re) ⇒ Object



17
18
19
# File 'lib/oval/match.rb', line 17

def self.[](re)
  new(re)
end

Instance Method Details

#it_shouldObject



13
14
15
# File 'lib/oval/match.rb', line 13

def it_should
  "match #{re.inspect}"
end

#validate(thing, subject = nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/oval/match.rb', line 5

def validate(thing, subject = nil)
  unless re.match(thing)
    raise Oval::ValueError,
      "Invalid value #{thing.inspect}#{for_subject(subject)}. " +
      "Should #{it_should}"
  end
end