class Anodator::Validator::FormatValidator

Constants

ALL_ZENKAKU_REGEXP

Public Class Methods

new(target_expression, options = { }) click to toggle source
Calls superclass method Anodator::Validator::Base::new
# File lib/anodator/validator/format_validator.rb, line 12
def initialize(target_expression, options = { })
  super(target_expression, options)

  if @options[:format].is_a? String
    @options[:format] = Regexp.new("#{@options[:format]}")
  end
end

Public Instance Methods

format() click to toggle source
# File lib/anodator/validator/format_validator.rb, line 43
def format
  return @options[:format].dup
end
validate() click to toggle source
# File lib/anodator/validator/format_validator.rb, line 20
def validate
  if target_value.split(//).size.zero?
    if allow_blank?
      return true
    end
  end


  if @options[:all_zenkaku]
    return target_value !~ ALL_ZENKAKU_REGEXP
  else
    unless @options[:format].is_a? Regexp
      raise ConfigurationError.new(":format option must be Regexp object")
    end

    if @options[:format].match target_value
      return true
    else
      return false
    end
  end
end