Class: ProMotion::RegexValidator

Inherits:
Validator show all
Defined in:
lib/ProMotion/XLForm/validators/regex_validator.rb

Instance Attribute Summary collapse

Attributes inherited from Validator

#message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Validator

#isValid

Constructor Details

#initialize(message, regex) ⇒ RegexValidator

Returns a new instance of RegexValidator.



5
6
7
8
# File 'lib/ProMotion/XLForm/validators/regex_validator.rb', line 5

def initialize(message, regex)
  @message = message
  @regex = regex
end

Instance Attribute Details

#regexObject

Returns the value of attribute regex.



3
4
5
# File 'lib/ProMotion/XLForm/validators/regex_validator.rb', line 3

def regex
  @regex
end

Class Method Details

.validator(message, regex) ⇒ Object



16
17
18
# File 'lib/ProMotion/XLForm/validators/regex_validator.rb', line 16

def self.validator(message, regex)
  ProMotion::RegexValidator.new(message, regex)
end

Instance Method Details

#valid?(row) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/ProMotion/XLForm/validators/regex_validator.rb', line 10

def valid?(row)
  return nil if row.nil? || row.value.nil? || !row.value.is_a?(String)

  !@regex.match(row.value).nil?
end