Module: Uniqueness
- Defined in:
- lib/uniqueness/model.rb,
lib/uniqueness/engine.rb,
lib/uniqueness/version.rb,
lib/uniqueness/generator.rb
Defined Under Namespace
Modules: Model Classes: Engine
Constant Summary collapse
- VERSION =
'0.9.0'.freeze
Class Method Summary collapse
- .generate(opts = {}) ⇒ Object
- .uniqueness_ambigious_dictionary ⇒ Object
-
.uniqueness_default_options ⇒ Object
Default sorting options.
-
.uniqueness_dictionary ⇒ Object
Dictionary used for uniqueness generation.
- .uniqueness_numbers_dictionary ⇒ Object
Class Method Details
.generate(opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/uniqueness/generator.rb', line 3 def generate(opts = {}) ||= {} = .merge(opts) dict = uniqueness_dictionary - [:blacklist] dict -= [*(:A..:Z)].map(&:to_s) unless [:case_sensitive] dict -= uniqueness_ambigious_dictionary if [:type].to_sym == :human dict = uniqueness_numbers_dictionary if [:type].to_sym == :numbers code = Array.new([:length]).map { dict[rand(dict.length)] }.join "#{options[:prefix]}#{code}#{options[:suffix]}" end |
.uniqueness_ambigious_dictionary ⇒ Object
19 20 21 |
# File 'lib/uniqueness/generator.rb', line 19 def uniqueness_ambigious_dictionary [:b, :B, :o, :O, :q, :i, :I, :l, :L, :s, :S, :u, :U, :z, :Z, :g, 1, 2, 9, 5].map(&:to_s) end |
.uniqueness_default_options ⇒ Object
Default sorting options
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/uniqueness/generator.rb', line 28 def { length: 32, type: :auto, blacklist: [], scope: [], suffix: '', prefix: '' } end |
.uniqueness_dictionary ⇒ Object
Dictionary used for uniqueness generation
15 16 17 |
# File 'lib/uniqueness/generator.rb', line 15 def uniqueness_dictionary [*(:A..:Z), *(:a..:z), *(0..9)].map(&:to_s) end |
.uniqueness_numbers_dictionary ⇒ Object
23 24 25 |
# File 'lib/uniqueness/generator.rb', line 23 def uniqueness_numbers_dictionary [*(0..9)].map(&:to_s) end |