From ff89415afd1cf637fc81755c39a323119d9e89bd Mon Sep 17 00:00:00 2001 From: Leonardo Diez Date: Wed, 4 Oct 2017 18:17:16 +0200 Subject: [PATCH] Added usage in README --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3319296..e48490a 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,48 @@ When IBAN validation is not enough. [![Dependency Status](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85?style=flat) ## Features -* IBAN validation (`ActiveModel::EachValidator` and control digits calculator function) +* IBAN validation (`ActiveModel::EachValidator` and control digits calculator function). * National account digits control validation (currently only ES included, others countries can be added). -* BICs mapping from IBAN bank code part: COUNTRY + BANK => BIC code +* Associated tags to countries (currently only SEPA tag is available). +* BICs mapping from IBAN bank code part: COUNTRY + BANK => BIC code. * Currently, static data only includes some ES banks, PRs are welcomed. * Optional database model to allow apps to dynamically add new BICs mapping. +## Usage + +1. Validator: add IBAN validation to your models. + +```ruby +validates :iban, iban: true +``` + +You can also validate that IBAN is from a SEPA country. + +```ruby +validates :iban, iban: { tags: [:sepa] } +``` + +2. IBAN control digits calculation + +```ruby +2.4.1 :001 > IbanBic.calculate_check("ES0000030000300000000000") + => 87 +``` + +3. IBAN parsing + +```ruby +2.4.1 :001 > IbanBic.parse("ES8700030000300000000000") +=> {"country"=>"ES", "iban_check"=>"87", "bank"=>"0003", "branch"=>"0000", "check"=>"30", "account"=>"0000000000"} +``` + +4. BIC calculation (bank code must be in the static file or in the database) + +```ruby +2.4.1 :009 > IbanBic.calculate_bic("ES8700030000300000000000") + => "BDEPESM1XXX" +``` + ## Installation 1. Add this line to your application's Gemfile @@ -29,7 +65,7 @@ $ bundle 3. Run installer -3.1. Using BICs dynamic data from database +3.a. Using BICs dynamic data from database Add a `bics` table to your database and an initializer file for configuration: @@ -44,7 +80,7 @@ Load static data to the created `bics` table: $ bundle exec rake iban_bic:load_data ``` -3.2. Using static data from YAML files +3.b. Using static data from YAML files Create an initializer file for configuration: