项目作者: sasalatart

项目描述 :
Ruby gem to validate UC alumni identifier numbers.
高级语言: Ruby
项目地址: git://github.com/sasalatart/uc-number-validator.git
创建时间: 2016-08-20T16:19:52Z
项目社区:https://github.com/sasalatart/uc-number-validator

开源协议:MIT License

下载


UC Number Validator

Provides a UC Student Number (número de alumno de la Pontificia Universidad Católica de Chile) validation method for a string or a model’s attribute.

Credits to Patricio López for his JS implementation.

Gem Version
Code Climate
Build Status
Coverage Status

Installation

Add this line to your application’s Gemfile:

gem 'uc_number_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uc_number_validator

Usage

If you want to validate a single string:

  1. require 'uc_number_validator' # Unless working with Ruby on Rails
  2. '1263476J'.valid_uc_number?
  3. => true
  4. '1263476-J'.valid_uc_number?
  5. => false

If you want to validate a model attribute you just need to set uc_number: true (like any model validation in Ruby on Rails):

  1. class User < ActiveRecord::Base
  2. attr_accessor :student_number
  3. validates :student_number, uc_number: true
  4. end

Contributing

  1. Fork this repository
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'add my feature')
  4. Push to your feature branch (git push origin my-new-feature)
  5. Create a new Pull Request