Class: Cure::Validator::LengthRule

Inherits:
BaseRule
  • Object
show all
Defined in:
lib/cure/validator/base_rule.rb

Instance Method Summary collapse

Methods inherited from BaseRule

#initialize

Constructor Details

This class inherits a constructor from Cure::Validator::BaseRule

Instance Method Details

#maxObject



57
58
59
# File 'lib/cure/validator/base_rule.rb', line 57

def max
  @max || @options.fetch(:max, 99_999)
end

#minObject



53
54
55
# File 'lib/cure/validator/base_rule.rb', line 53

def min
  @min || @options.fetch(:max, 0)
end

#process(value) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/cure/validator/base_rule.rb', line 41

def process(value)
  return true if value.nil?
  return true unless value.respond_to? :size

  length = value.size
  length >= min && length <= max
end

#to_sObject



49
50
51
# File 'lib/cure/validator/base_rule.rb', line 49

def to_s
  "Length [Min: #{min}, Max: #{max}]"
end