Sha256: 294bc612758b98253e3da35ebc92354ef9f624b27a2688b6d436899f35e45efc

Contents?: true

Size: 514 Bytes

Versions: 10

Compression:

Stored size: 514 Bytes

Contents

# frozen_string_literal: true

class AlphaValidator < BaseValidator

  CASES ||= {
    lower: 'a-z',
    upper: 'A-Z',
    any: 'A-Za-z'
  }.freeze

  def validate_each(record, attribute, value)
    assert_valid_case!
    super
  end

  private

  def assert_valid_case!
    assert_valid_option!(:case, CASES.keys, option: kase)
  end

  def kase
    options[:case] || :any
  end

  def regexp
    /^[#{CASES[kase]}#{' ' if options[:allow_space]}]+$/
  end

  def valid_regexp?
    value.to_s =~ regexp
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lite-validators-1.1.1 lib/lite/validators/alpha_validator.rb
lite-validators-1.1.0 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.7 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.6 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.5 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.4 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.3 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.2 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.1 lib/lite/validators/alpha_validator.rb
lite-validators-1.0.0 lib/lite/validators/alpha_validator.rb