class Bodhi::LengthValidator
Attributes
value[R]
Public Class Methods
new(value)
click to toggle source
# File lib/bodhi-slam/validators/length.rb, line 5 def initialize(value) @value = value end
Public Instance Methods
to_options()
click to toggle source
# File lib/bodhi-slam/validators/length.rb, line 23 def to_options {self.to_sym => @value} end
validate(record, attribute, value)
click to toggle source
# File lib/bodhi-slam/validators/length.rb, line 9 def validate(record, attribute, value) unless value.nil? if value.is_a?(Array) unless value.empty? record.errors.add(attribute, "must all be #{@value} characters long") unless value.select{ |item| !item.length.between?(@value.first, @value.last) }.empty? end else record.errors.add(attribute, "must be #{@value} characters long") unless value.length.between?(@value.first, @value.last) end end end