Project

cns_brazil

0.0
No release in over a year
CNS is a national health card from Brazil
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 3.12.0
= 1.38.0

Runtime

 Project Readme

CNS Brazil

Usage

Installing

Add this line to your application's Gemfile:

gem 'cns_brazil'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cns_brazil

Validator

ActiveRecord

  • Just use as any other validator:
class User < ActiveRecord::Base
  validates :cns, '::CnsBrazil::Cns': true
end
  • Use with anny column name
class User < ActiveRecord::Base
  validates :my_cns, '::CnsBrazil::Cns': true
end
  • Allow blank value
class User < ActiveRecord::Base
  validates :cns, '::CnsBrazil::Cns': true, allow_blank: true
end

Elsewhere

require "cns_brazil"

cns_validator = CnsBrazil::Cns.new(value: '1234567891234516')

cns_validator.valid? # true || false

Generator

require "cns_brazil"

CnsBrazil::Cns.generate  # returns a valid CNS

Test

Obs: If your project has shoulda-matchers gem you can use next matcher

Create a file spec/support/cns_brazil.rb and add next content

require 'cns_brazil/validate_cns_matcher'

Use in your tests:

specify { is_expected.to validate_cns } # It will test the attribute :cns by default
specify { is_expected.to validate_cns(:my_cns) }

With blank value

specify { is_expected.to validate_cns.allow_blank }
specify { is_expected.to validate_cns(:my_cns).allow_blank }

Usage example

Contributing

  • Run using Docker: docker-compose run web bash
  • In bash Run: bundle install
  • Run spec: spec
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request