Class: NiceId::Id

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

Constant Summary collapse

VARS_NUM =
%w{2 3 4 5 6 7 8 9}
VARS_LET =
%w{f j k m p s t v w x y z e}
DEFAULT_SIZE =
3

Instance Method Summary collapse

Constructor Details

#initialize(how_many = DEFAULT_SIZE) ⇒ Id

Returns a new instance of Id.



7
8
9
10
11
12
# File 'lib/niceid.rb', line 7

def initialize(how_many = DEFAULT_SIZE)
  rand_method = [].respond_to?(:sample) ? :sample : :choice
  @key = [].fill(0, how_many) { [VARS_NUM.send(rand_method),VARS_LET.send(rand_method)] }
  @key = @key.flatten.join
  @key = @key.chop + calc(@key)
end

Instance Method Details

#to_sObject



14
15
16
# File 'lib/niceid.rb', line 14

def to_s
  @key
end