Class: Mayu::VDOM::IdGenerator
- Inherits:
-
Object
- Object
- Mayu::VDOM::IdGenerator
- 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
-
#initialize ⇒ IdGenerator
constructor
A new instance of IdGenerator.
- #marshal_dump ⇒ Object
- #marshal_load(counter) ⇒ Object
- #next! ⇒ Object
Constructor Details
#initialize ⇒ IdGenerator
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_dump ⇒ Object
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 |