class TwitterSnowflake::Snowflake
A snowflake ID as a Ruby object.
Attributes
@return [Integer] the base epoch in milliseconds to perform calculations.
@return [Integer] the snowflake ID in its original form.
@return [Integer] the increment extracted from the ID.
@return [Integer] the proccess ID extracted from the ID.
@return [Time] the timestamp as a Time object
@return [Integer] the timestamp extracted from the ID in milliseconds.
@return [Integer] the worker ID extracted form the ID.
Public Class Methods
@param id [Integer] the ID itself. @param epoch [Intger] base epoch in milliseconds to perform calculations.
# File lib/twitter_snowflake/snowflake.rb, line 29 def initialize(id:, epoch:) # Data used during extraction process @id = id @epoch = epoch # Extracting data @timestamp = TwitterSnowflake.timestamp(@id, epoch: @epoch) @worker_id = TwitterSnowflake.worker_id(@id) @process_id = TwitterSnowflake.process_id(@id) @increment = TwitterSnowflake.increment(@id) # Useful information @time = Time.at(@timestamp / 1000.0) end
Public Instance Methods
Checks if two snowflakes are equal. Two snowflakes are considered equal if both have the same ID and are based on the same epoch.
@param other [Snowflake] the other snowflake.
@return [Boolean] whether the snowflakes are equal or not.
# File lib/twitter_snowflake/snowflake.rb, line 50 def ==(other) (@id == other.id) && (@epoch == other.epoch) end
Checks if this snowflake has been generated after another snowflake.
@param other [Snowflake] the other snowflake.
@return [Boolean] whether this snowflake has been generated after another snowflake or not.
# File lib/twitter_snowflake/snowflake.rb, line 68 def after?(other) @timestamp > other.timestamp end
Checks if this snowflake has been generated before another snowflake.
@param other [Snowflake] the other snowflake.
@return [Boolean] whether this snowflake has been generated before another snowflake or not.
# File lib/twitter_snowflake/snowflake.rb, line 59 def before?(other) @timestamp < other.timestamp end