class SnowflakeId
Provides Twitter's snowflake-encoded status ID to Time
conversion
Constants
- SNOWFLAKE_EPOCH_MILLIS
- VERSION
Public Class Methods
new(id)
click to toggle source
Generates Snowflake object from Twitter's status ID.
# File lib/snowflake-id.rb, line 12 def initialize(id) @id = id.to_i end
to_snowflake(time)
click to toggle source
Converts Time
object into Snowflake object.
# File lib/snowflake-id.rb, line 45 def self.to_snowflake(time) millis = (time.to_f * 1000).to_i if millis < SNOWFLAKE_EPOCH_MILLIS raise "#{time} is before Snowflake epoch" end return SnowflakeId.new((millis - SNOWFLAKE_EPOCH_MILLIS) << 22) end
Public Instance Methods
==(other)
click to toggle source
# File lib/snowflake-id.rb, line 38 def ==(other) return @id == other.id end
id()
click to toggle source
Returns snowflake-encoded ID.
# File lib/snowflake-id.rb, line 19 def id return @id end
to_s()
click to toggle source
Returns string representation of ID
# File lib/snowflake-id.rb, line 26 def to_s return @id.to_s end
to_time()
click to toggle source
Returns Time
object which is included in snowflake-encoded ID.
# File lib/snowflake-id.rb, line 33 def to_time t = ((@id >> 22) + SNOWFLAKE_EPOCH_MILLIS) / 1000.0 return Time.at(t) end