Class: Compel::Validation::Format

Inherits:
Condition
  • Object
show all
Defined in:
lib/compel/validation/conditions/format.rb

Instance Attribute Summary

Attributes inherited from Condition

#option_value, #options, #value, #value_type

Instance Method Summary collapse

Methods inherited from Condition

#initialize, validate, #validate

Constructor Details

This class inherits a constructor from Compel::Validation::Condition

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/compel/validation/conditions/format.rb', line 12

def valid?
  !value.nil? && value =~ option_value
end

#validate_valueObject



6
7
8
9
10
# File 'lib/compel/validation/conditions/format.rb', line 6

def validate_value
  if value_type == Coercion::String && !valid?
    "must match format #{option_value.source}"
  end
end