class TimespanValidator
Attributes
attrib[R]
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/timespan_validator.rb, line 4 def validate_each(record, attribute, value) @attrib = attribute record.errors[attribute] << "must be within: #{show_range}" unless within? value end
Protected Instance Methods
from()
click to toggle source
# File lib/timespan_validator.rb, line 18 def from options[:from] end
show_range()
click to toggle source
# File lib/timespan_validator.rb, line 26 def show_range "#{from} - #{to}" end
to()
click to toggle source
# File lib/timespan_validator.rb, line 22 def to options[:to] end
within?(value)
click to toggle source
# File lib/timespan_validator.rb, line 11 def within? value return true if value.nil? raise ArgumentError, "#{attrib} must be a Timespan, was: #{value}" unless value.kind_of?(Timespan) # puts "value: #{value} between? #{from} and #{to}" value.between?(from, to) end