Class: Schash::Schema::Rule::Match

Inherits:
Base
  • Object
show all
Defined in:
lib/schash/schema/rule/match.rb

Instance Method Summary collapse

Methods inherited from Base

#optional?

Constructor Details

#initialize(pattern) ⇒ Match

Returns a new instance of Match.



5
6
7
# File 'lib/schash/schema/rule/match.rb', line 5

def initialize(pattern)
  @pattern = pattern
end

Instance Method Details

#validate(target, position = []) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/schash/schema/rule/match.rb', line 9

def validate(target, position = [])
  errors = []

  unless @pattern.match(target)
    errors << Error.new(position, "does not match #{@pattern.inspect}")
  end

  errors
end