Sha256: a847bad72d0427c63ea76b7aaf5216b9eb55419a7a48716108b4f631a9baa42f

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

# Mascherari

[![Gem Version](https://badge.fury.io/rb/mascherari.png)](https://badge.fury.io/rb/mascherari)
[![Build Status](https://travis-ci.org/robsonmarques/mascherari.png)](https://travis-ci.org/robsonmarques/mascherari)
[![Code Climate](https://codeclimate.com/github/robsonmarques/mascherari.png)](https://codeclimate.com/github/robsonmarques/mascherari)

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:

```ruby
class Person
  include Mascherari

  attr_accessor :phone

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

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

```ruby
# 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:

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

And also use a different wildcard, if needed:

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

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

```ruby
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:

```ruby
# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mascherari-0.0.2 README.md