This gem provides classes to validate personal information specific to Argentina like CUIT or CBU.
Add this line to your application's Gemfile:
gem 'argentinian-validations'
And then execute:
$ bundle
Or install it yourself as:
$ gem install argentinian-validations
require 'argentinian/validations'
valid_cbu = '2850590940090418135201'
validator = Argentinian::Validations::Cbu.new(valid_cbu)
validator.valid? #=> true
validator.validate! #=> "2850590940090418135201"
invalid_cbu = '1850590940090418135201'
validator = Argentinian::Validations::Cbu.new(invalid_cbu)
validator.valid? #=> false
validator.validate! #=> *** Argentinian::Validations::Cbu::AccountError Exception
valid_cuit = '30707026851'
validator = Argentinian::Validations::Cuit.new(valid_cuit)
validator.valid? #=> true
validator.validate! #=> "30707026851"
invalid_cuit = '20707026851'
validator = Argentinian::Validations::Cuit.new(invalid_cuit)
validator.valid? #=> false
validator.validate! #=> *** Argentinian::Validations::Cuil::InvalidNumberError Exception
It is very useful to use the custom validators provided by Rails:
# app/validators/cbu_validator.rb
class CbuValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
validator = Argentinian::Validations::Cbu.new(value)
record.errors.add(attribute, validator.errors.first) unless validator.valid?
end
end
And then in your model:
# app/models/my_model.rb
class MyModel < ApplicationRecord
validates :number, cbu: true
end
After checking out the repo, run bundle install
to install dependencies.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run rubocop (
bundle exec rubocop Gemfile lib spec
) - Run rspec (
bundle exec rspec
) - Push your branch (
git push origin my-new-feature
) - Create a new Pull Request