Class: Mayu::VDOM::IdGenerator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/vdom/id_generator.rb

Constant Summary collapse

ALPHABET =

ALPHABET = "πŸŒ±πŸŒ΄πŸŒ΅πŸŒΈπŸŒΊπŸŒ»πŸŒΌπŸŒΏπŸ€πŸƒ" JOINER = ""

"0123456789"
JOINER =
""
DIGITS =
T.let(ALPHABET.chars.freeze, T::Array[String])
Type =
T.type_alias { String }

Instance Method Summary collapse

Constructor Details

#initializeIdGenerator

Returns a new instance of IdGenerator.



18
19
20
# File 'lib/mayu/vdom/id_generator.rb', line 18

def initialize
  @counter = T.let(0, Integer)
end

Instance Method Details

#marshal_dumpObject



29
30
31
# File 'lib/mayu/vdom/id_generator.rb', line 29

def marshal_dump
  @counter
end

#marshal_load(counter) ⇒ Object



34
35
36
# File 'lib/mayu/vdom/id_generator.rb', line 34

def marshal_load(counter)
  @counter = counter
end

#next!Object



23
24
25
26
# File 'lib/mayu/vdom/id_generator.rb', line 23

def next!
  id = @counter.tap { @counter = @counter.succ }
  number_to_base(id, DIGITS.length).map { DIGITS[_1] }.join(JOINER)
end