class ActiveRecord::Normalizations::TextTransformNormalizer

Constants

VALID_TRANSFORMATIONS

Public Class Methods

new(options) click to toggle source
# File lib/activerecord-normalizations/normalizers/text_transform_normalizer.rb, line 5
def initialize(options)
  @transformation = options[:with]

  if !VALID_TRANSFORMATIONS.include?(@transformation)
    raise ArgumentError, "#{@transformation} must be one of #{VALID_TRANSFORMATIONS}"
  end
end

Public Instance Methods

call(attr) click to toggle source
# File lib/activerecord-normalizations/normalizers/text_transform_normalizer.rb, line 13
def call(attr)
  case @transformation
  when :uppercase
    attr.upcase
  when :lowercase
    attr.downcase
  when :word_capitalize
    attr.gsub(/[[:alpha:]]+/, &:capitalize)
  else
    attr.capitalize
  end
end