Class: Shogun::Verifier::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/shogun/verifier/match.rb

Instance Method Summary collapse

Constructor Details

#initialize(data:, name:, comparison:) ⇒ Match

Returns a new instance of Match.



4
5
6
7
8
# File 'lib/shogun/verifier/match.rb', line 4

def initialize(data:, name:, comparison:)
  @data = data
  @name = name
  @comparison = comparison
end

Instance Method Details

#contextObject



22
23
24
25
26
27
28
# File 'lib/shogun/verifier/match.rb', line 22

def context
  if @comparison.is_a?(Regexp)
    {
      "pattern" => @comparison
    }
  end
end

#idObject



18
19
20
# File 'lib/shogun/verifier/match.rb', line 18

def id
  "#{@name}_does_not_match"
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/shogun/verifier/match.rb', line 10

def valid?
  if @comparison.is_a?(Regexp)
    @data =~ @comparison
  else
    @data == @comparison || @comparison == @data
  end
end