class ActiveRecord::Normalizations::SpacesNormalizer

Constants

VALID_TYPES

Public Class Methods

new(options) click to toggle source
# File lib/activerecord-normalizations/normalizers/spaces_normalizer.rb, line 5
def initialize(options)
  type = options[:with] || :both
  raise ArgumentError, "#{type} must be one of #{VALID_TYPES}" if !VALID_TYPES.include?(type)

  @method = determine_method(type)
end

Public Instance Methods

call(attr) click to toggle source
# File lib/activerecord-normalizations/normalizers/spaces_normalizer.rb, line 12
def call(attr)
  attr.send(@method)
end

Private Instance Methods

determine_method(type) click to toggle source
# File lib/activerecord-normalizations/normalizers/spaces_normalizer.rb, line 18
def determine_method(type)
  case type
  when :leading
    :lstrip
  when :trailing
    :rstrip
  else
    :strip
  end
end