Class: Decidim::Meetings::Registrations::CodeGenerator
- Inherits:
-
Object
- Object
- Decidim::Meetings::Registrations::CodeGenerator
- Defined in:
- lib/decidim/meetings/registrations/code_generator.rb
Overview
This class handles the generation of meeting registration codes
Constant Summary collapse
- ALPHABET =
excluded digits: 0, 1, excluded letters: O, I
[*"A".."Z", *"2".."9"] - %w(O I)
- LENGTH =
8
Instance Method Summary collapse
- #generate(registration) ⇒ Object
-
#initialize(options = {}) ⇒ CodeGenerator
constructor
A new instance of CodeGenerator.
Constructor Details
#initialize(options = {}) ⇒ CodeGenerator
Returns a new instance of CodeGenerator.
14 15 16 |
# File 'lib/decidim/meetings/registrations/code_generator.rb', line 14 def initialize( = {}) @length = [:length] || LENGTH end |
Instance Method Details
#generate(registration) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/decidim/meetings/registrations/code_generator.rb', line 18 def generate(registration) loop do registration_code = choose(@length) # Use the random number if no other registration exists with it. break registration_code unless registration.class.exists?(meeting: registration.meeting, code: registration_code) end end |