Project

mascherari

0.0
No commit activity in last 3 years
No release in over 3 years
An easy way to handle masks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
~> 2.12
 Project Readme

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