Class: PuushIDGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/puushload/puush_id_generator.rb

Constant Summary collapse

CHARS =
("0".."9").to_a + ("a".."z").to_a + ("A".."Z").to_a

Class Method Summary collapse

Class Method Details

.generate(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puushload/puush_id_generator.rb', line 4

def self.generate(&block)
  
  # this is really fuckin dirty atm, but you may optimize this if you want to
  
  # Example-ID: 12345
  
  # first char (1) Only Numbers at the moment. Should take a bit until chars are being used here
  ("1".."9").each do |char1|
    # second char (2)
    CHARS.each do |char2|
      # third char (3)
      CHARS.each do |char3|
        # fourth char (4)
        CHARS.each do |char4|
          # fifth char (5)
          CHARS.each do |char5|
            # combine se IDs
            id = char1 + char2 + char3 + char4 + char5
            # call se block
            block.call(id)
          end
        end
      end
    end
  end
end