Class: NiceId::Id
- Inherits:
-
Object
- Object
- NiceId::Id
- 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}
- DEFAULT_SIZE =
3
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #correct? ⇒ Boolean
-
#initialize(how_many = DEFAULT_SIZE) ⇒ Id
constructor
A new instance of Id.
- #to_s ⇒ Object
Constructor Details
#initialize(how_many = DEFAULT_SIZE) ⇒ Id
Returns a new instance of Id.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/niceid.rb', line 9 def initialize(how_many = DEFAULT_SIZE) @key = '' @summ = 0 how_many.times do a = rand VARS_NUM.size b = rand VARS_LET.size @key<<VARS_NUM[a]+VARS_LET[b] end @key=@key.chop << calc end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/niceid.rb', line 7 def key @key end |
Instance Method Details
#correct? ⇒ Boolean
22 23 24 |
# File 'lib/niceid.rb', line 22 def correct? @key[-1..-1] == calc end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/niceid.rb', line 19 def to_s @key end |