Services and validations for government-issued health cards.
In your Gemfile, add the following line:
gem 'health_card', git: 'https://github.com/petalmd/health_card.git', branch: 'master'
and then run bundle install
. You will then have access to HealthCard's methods.
A card value can be validated by means of the following methods:
Validates the specified card value.
Usage:
HealthCard.card_valid?(card_value, iso3166_code, options)
Parameters:
card_value
(String
): the card value to be validated.iso3166_code
(String
): the ISO 3166 code that represents the country or country subdivision against which the card value should be validated.options
(Hash
): extra informations about the card that may affect the card value's validation (eg. first and last name of the card bearer). Also contains theskip_checksum
flag, which will tell the validator not to validate the checksum.
Return value:
true
or false
, whether the card value was determined to be valid or not.
Notes:
The .card_valid!
version of the method will raise an InvalidCardValueError
instead of returning false
.
A card value can be converted to other useful formats. The following methods are available:
Strips the specified card value to the bare minimum. Basically, it removes diacritics and all non-alphanumeric characters.
Usage:
HealthCard.sanitize(card_value, iso3166_code)
Parameters:
card_value
(String
): the card value to be sanitized.iso3166_code
(String
): the ISO 3166 code that represents the country or country subdivision for which the card value should be sanitized.
Return value:
The stripped-down card value.
Formats the specified card value to how it would look like on an official card.
Usage:
HealthCard.beautify(card_value, iso3166_code)
Parameters:
card_value
(String
): the card value to be beautified.iso3166_code
(String
): the ISO 3166 code that represents the country or country subdivision for which the card value should be displayed.
Return value:
The card value in the country or country subdivision's official format.
Notes:
This method validates the card value first. If the card value is not valid, it will not be changed. The .beautify!
version of the method will raise an InvalidCardValueError
instead.
Available countries or country subdivisions are:
- CA-ON (Canada, Ontario)
- CA-QC (Canada, Quebec)