Giter Site home page Giter Site logo

iso4217-validator's Introduction

Iso4217::Validator

Simple ruby on rails validator that checks if a value is a valid [ISO4217] (http://en.wikipedia.org/wiki/ISO_4217) code.

Examples of ISO4217 codes: EUR, USD, CHF, TWD, INR.

Installation

Add this line to your application's Gemfile:

gem 'iso4217-validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install iso4217-validator

Usage

Include the validator in your model attribute this way:

  class TestModel < ActiveRecord::Base
    include Iso4217::Validator
    validates :currency_code, iso4217Code: true 
  end

currency_code attribute shall be defined as an string.

If the currency_code is invalid the validator adds an :invalid message error. If you want to customize the error message you can use:

  class TestModel < ActiveRecord::Base
    include Iso4217::Validator
    validates :currency_code, iso4217Code: {message: "Oh! That's an invalid currency code."}
  end

Please bear in mind that the validator is case sensitive. So 'EUR' is a valid code but 'eur' is not.

Contributing

  1. Fork it ( http://github.com/merlos/iso4217-validator/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature with tests')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Please add unit tests when including new features.

Maintaining the list updated

Source of the valid code list used: http://www.currency-iso.org/en/home/tables/table-a1.html The last version included in the gem: August 15, 2014.

The gem source includes an script (bin/extractor.rb) that can extract the codes from the excel file and convert it into the ruby array which is used by the validator. You can find more instructions within the extractor.rb file.

License

Copyright (c) 2014 Juan M. Merlos. Distributed under MIT License

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.