Skip to content

robsonmarques/mascherari

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mascherari

Gem Version Build Status Code Climate

An easy way to handle masks. (Work in progress)

Installation

Simple as:

$ gem install mascherari

Usage

To create masks for attributes, include Mascherari and set the format:

class Person
  include Mascherari

  attr_accessor :phone

  attr_masked :phone, :format => "(##) ####-####"
end

That will give you two helpers to use along with the object:

# person.phone = "5554212035"
person.phone_masked
=> "(55) 5421-2035"

# person.phone = "(55) 5421-2035"
person.phone_unmasked
=> "5554212035"

You can set a format for more than one attribute:

attr_masked :phone, :mobile, :format => "(##) ####-####"

And also use a different wildcard, if needed:

attr_masked :phone, :format => "(**) ****-****", :wildcard => "*"

For the cases when format can vary, it's possible to set multiple formats:

attr_masked :phone, :format => ["(##) ####-####", "(###) ####-####"]

Rails

Add this line to your application's Gemfile:

gem 'mascherari'

And then execute:

$ bundle

You can include Mascherari in Rails models as:

# config/initializers/mascherari.rb
ActiveSupport.on_load :active_record do
  include Mascherari
end

# app/models/person.rb
class Person < ActiveRecord::Base
  attr_masked :phone, :format => "(##) ####-####"
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

An easy way to handle masks

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages