Skip to content

Houdini/attribute_normalizer

 
 

Repository files navigation

Attribute Normalizer

It’s fork of Attribute normalizer, but for cassandra_object. It’s ready to use.


class Klass < CassandraObject::Base
  attribute :first_name, :type => String
  attribute :last_name, :type => String

  # Can take an array of attributes if you want
  normalize_attributes :first_name, :last_name

  normalize_attributes :home_phone_number, :office_phone_number_ do |value|
    value.is_a?(String) ? value.gsub(/\W/, '').gsub(/^1/, '') : nil
  end

end

object = Klass.new
# Blank normalizes to nil
object.first_name = ''
object.first_name # => nil

# Whitespace is cleaned up
object.last_name = "\tDeering\n"
object.last_name # => 'Deering'

# Your given block will be executed to normalize
object.home_phone_number = '+1 (555) 123.4567'
object.home_phone_number # => '5551234567'

Copyright
MIT-LICENSE

About

Adds the ability to normalize and format attributes cleanly with code blocks. For cassandra_object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%