GithubHelp home page GithubHelp logo

damjack / codice_fiscale Goto Github PK

View Code? Open in Web Editor NEW

This project forked from topac/codice_fiscale

0.0 1.0 0.0 408 KB

A ruby gem that calculate the italian fiscal code

License: MIT License

Ruby 100.00%

codice_fiscale's Introduction

Codice fiscale

A ruby gem to support the calculation of the italian fiscal code ("Cofice fiscale"), that is an ID assigned to each italian citizen by the "Agenzia delle entrate".

To calculate the fiscal code you need the following information: name, surname, gender, birthdate and the birthplace. Read more on wikipedia.

Usage

  require 'codice_fiscale'

  CodiceFiscale.calculate :name => 'Mario', :surname => 'Rossi', :gender => :male, :birthdate => Date.new(1987, 1, 1), :province_code => 'LC', :city_name => 'Abbadia Lariana'

  # RSSMRA87A01A005V

City codes (Codici catastali)

As explained above, one of the information required to calculate the fiscal code is the birthplace.
If a person was born outside Italy, only the italian name of the county is required.
For example, an italian citizen born in France:

  CodiceFiscale.calculate :name => 'Mario', :surname => 'Rossi', :gender => :male, :birthdate => Date.new(1987, 1, 1), :country_name => 'Francia'

If a person was born in Italy you have to specify the code of the province and the name of the city. These informations are actually contained in an XLS document downloaded from agenziaterritorio.it, converted to CSV and shipped with this gem.

But what if you have your own table with all those codes?

In this case, you can add a custom block that fetches the codes from your tables/files:

config/initializers/codice_fiscale_initializer.rb:

  # Fetching the codes using ActiveRecord:

  CodiceFiscale.config.country_code do |country_name|
    Country.find_by_name(country_name).code
  end

  CodiceFiscale.config.city_code do |city_name, province_code|
    City.in_italy.find_by_province_and_city(province_code, city_name).code
  end

Installation

I'm currently supporting only ruby 1.9+

Note: The gem name on rubygems.org is "codice-fiscale" not "codice_fiscale"

Add this line to your application's Gemfile:

gem 'codice-fiscale'

And then execute:

$ bundle

Testing

I'm using RSpec + guard (+ growl for notifications)

$ bundle exec guard

Contributing

  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

codice_fiscale's People

Contributors

cedum avatar topac avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.