SNILS
Generating, validating and formatting SNILS number (Russian pension insurance individual account number).
Генерация, валидация и форматирование СНИЛС (Страхового номера индивидуального лицевого счёта).
Read this README in Russian (Читать это README на русском)
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:
Snils.new.formatted
#=> "216-471-647 63"
Validate SNILS:
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:
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
- Fork it ( https://github.com/Envek/snils/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request