vitorcavalcanti / coupon-code

Generate and validate coupon codes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Code Climate Test Coverage Gem Version

CouponCode

README-한국어

CouponCode gem generates and validates coupon codes that are suitable for e-commerce services and businesses.

It is a Ruby implementation of Grant's Algorithm::CouponCode. Please read the original documentation of Algorithm::CouponCode for more details.

Please be aware that some of the original CPAN module's features are not implemented yet. For example, generating codes by plaintext, auto correction, and jQuery plugin are missing in this gem.

This gem is developed for https://stripes.co.kr

Installation

Add this line to your application's Gemfile:

gem 'coupon_code'

And then execute:

$ bundle

Or install it yourself as:

$ gem install coupon_code

Synopsis

>> require 'coupon_code'
>> code = CouponCode.generate
=> "1K7Q-CTFM-LMTC"
>> CouponCode.validate(code)
=> "1K7Q-CTFM-LMTC"
>> CouponCode.validate('1K7Q-CTFM-LMTO') # Invalid code
=> nil

Options

You can change the number of parts of the generated code by passing an option hash value like:

>> CouponCode.generate(parts: 4)
=> "1K7Q-CTFM-LMTC-DLGP"
>> CouponCode.validate("1K7Q-CTFM-LMTC-DLGP", 4)
=> "1K7Q-CTFM-LMTC-DLGP"

Testing

$ bundle exec rake spec

Thanks to

License

MIT. See LICENSE for more details.

Contributing

  1. Fork it ( https://github.com/baxang/coupon-code/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Generate and validate coupon codes.

License:MIT License


Languages

Language:Ruby 100.0%