Adds easy to use identifier creation mechanism.
Add this line to your application's Gemfile:
gem 'identify_it'
And then execute:
$ bundle
Or install it yourself as:
$ gem install identify_it
Add migration to your project
class YourModelName < ActiveRecord::Migration
def up
add_column :your_model_name, :string
end
def down
remove_column :your_model_name, :string
end
end
Just add to your ActiveRecord model a DSL instuction:
has_identifier(format, options)
format - string
options - hash of symbols
With format you are defining how identifier will look like. Main syntax is that a curly brackets you are defining how long each literal would be.
{4}:{5} -> ABCD:ABCDE
In options you can specify:
- alphabet (:letters, :numbers, :mix)
- case (:upper, :lower, :mix)
##Examples
has_identifier('AA:{2}-{4}', alphabet: :numbers)
> 'AA:34-1324'
has_identifier('{3}:{3}', alphabet: :mix, case: :upper)
> 'A22:8BS'
has_identifier('{8}', alphabet: :mix, case: :mix)
> '1s5DFG67'
The gem is available as open source under the terms of the MIT License.