class AmericanDateParsing::AmericanDateValidator::Validation

Attributes

options[R]
raw[R]
value[R]

Public Class Methods

new(options) click to toggle source
# File lib/american_date_parsing.rb, line 68
def initialize(options)
  @value   = options[:value]
  @raw     = options[:raw]
  @options = options[:options]
end

Public Instance Methods

errors() click to toggle source
# File lib/american_date_parsing.rb, line 74
def errors
  [format_error, presence_error].compact
end

Private Instance Methods

blank?() click to toggle source
# File lib/american_date_parsing.rb, line 90
def blank?
  value.blank? && raw.blank?
end
format_error() click to toggle source
# File lib/american_date_parsing.rb, line 86
def format_error
  [:invalid, options[:format]] if validate_format? && format_mismatch?
end
format_mismatch?() click to toggle source
# File lib/american_date_parsing.rb, line 94
def format_mismatch?
  raw.present? &&
  value.blank? &&
  raw !~ AmericanDateParsing.date_format
end
presence_error() click to toggle source
# File lib/american_date_parsing.rb, line 82
def presence_error
  [:blank, options[:presence]] if validate_presence? && blank?
end
validate_format?() click to toggle source
# File lib/american_date_parsing.rb, line 100
def validate_format?
  options[:format]
end
validate_presence?() click to toggle source
# File lib/american_date_parsing.rb, line 104
def validate_presence?
  options[:presence]
end