class Snowflakey::Snowflake

Constants

BASE

Attributes

base[R]
id[R]
prefix[R]
size[R]
time[R]

Public Class Methods

new(prefix, size, time, id, base) click to toggle source
# File lib/snowflakey/snowflake.rb, line 5
def initialize(prefix, size, time, id, base)
  @prefix = prefix
  @size   = size
  @time   = time
  @id     = id
  @base   = base.to_i
end

Public Instance Methods

inspect() click to toggle source
# File lib/snowflakey/snowflake.rb, line 23
def inspect
  to_s
end
to_s() click to toggle source
# File lib/snowflakey/snowflake.rb, line 14
def to_s
  t  = (@time.to_f * 1e3).round
  id = t << (@size - 41)
  id = id | @id % (2 ** (@size - 41))
  id = Baseconv.convert(id, from_base: 10, to_base: @base)

  [*@prefix, id].compact.join("_")
end