Skip to content

Commit

Permalink
Added usage in README
Browse files Browse the repository at this point in the history
  • Loading branch information
leio10 committed Oct 4, 2017
1 parent 0cc8864 commit ff89415
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand All @@ -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:

Expand Down

0 comments on commit ff89415

Please sign in to comment.