Class: Rulix::Validators::FormatValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rulix/validators/format_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ FormatValidator

Returns a new instance of FormatValidator.



6
7
8
9
10
11
# File 'lib/rulix/validators/format_validator.rb', line 6

def initialize options = nil
  options ||= {}

  self.format = options[:format]
  self.message = options.fetch :message, 'does not match format'
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/rulix/validators/format_validator.rb', line 4

def format
  @format
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'lib/rulix/validators/format_validator.rb', line 4

def message
  @message
end

Instance Method Details

#call(string) ⇒ Object



13
14
15
# File 'lib/rulix/validators/format_validator.rb', line 13

def call string
  format === string || [false, message]
end

#to_procObject



17
18
19
# File 'lib/rulix/validators/format_validator.rb', line 17

def to_proc
  method(:call)
end