Sha256: 22f5fa0a97d88f3b26a40822cb30d3a0dabdc2c041f220055b99bde4d11051cd

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

SNILS
=====

[![Gem Version](https://badge.fury.io/rb/snils.svg)](http://badge.fury.io/rb/snils)
[![Continuous Integration status](https://api.travis-ci.org/Envek/snils.svg)](http://travis-ci.org/Envek/snils)

Generating, validating and formatting [SNILS] number (Russian pension insurance individual account number).

Генерация, валидация и форматирование СНИЛС (Страхового номера индивидуального лицевого счёта).

[Read this README in Russian (Читать это README на русском)](README.ru.md)

## Installation

Add this line to your application's Gemfile:

    gem 'snils'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install snils

## Usage

Generate new SNILS:

```ruby
Snils.new.formatted
#=> "216-471-647 63"
```

Validate SNILS:

```ruby
Snils.new("21647164763").valid?
#=> true

Snils.new("21647164760").valid?
#=> false

Snils.new("21647164760").errors
#=> [:invalid]

Snils.new("216471647").errors
#=> [[:wrong_length, {:count=>11}], :invalid]
```

Validating Rails model attributes:

```ruby
require 'snils'

class User < ActiveRecord::Base
  validates :snils, presence: true, uniqueness: true
  validate  :snils_validation
  
  protected
  
  def snils_validation
    validated_snils = Snils.new(snils)
    unless validated_snils.valid?
      validated_snils.errors.each do |error|
        errors.add(:snils, *error)
      end
    end
  end
end
```

## Contributing

1. Fork it ( https://github.com/Envek/snils/fork )
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 a new Pull Request

[SNILS]: http://en.wikipedia.org/wiki/SNILS_(Russia) "Insurance individual account number"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
snils-0.1.2 README.md
snils-0.1.1 README.md
snils-0.1.0 README.md