class Discorb::Snowflake

Represents Snowflake of Discord.

@see discord.com/developers/docs/reference#snowflakes Official Discord API docs

Public Class Methods

new(value) click to toggle source

@!visibility private

# File lib/discorb/common.rb, line 44
def initialize(value)
  @value = value.to_i
end

Public Instance Methods

==(other) click to toggle source

Compares snowflake with other object.

@param [#to_s] other Object to compare with.

@return [Boolean] True if snowflake is equal to other object.

# File lib/discorb/common.rb, line 94
def ==(other)
  return false unless other.respond_to?(:to_s)

  to_s == other.to_s
end
eql?(other) click to toggle source

Alias of {#==}.

# File lib/discorb/common.rb, line 103
def eql?(other)
  self == other
end
hash() click to toggle source

Return hash of snowflake.

# File lib/discorb/common.rb, line 108
def hash
  to_s.hash
end
increment() click to toggle source
# File lib/discorb/common.rb, line 124
def increment
  @value & 0xFFF
end
process_id() click to toggle source
# File lib/discorb/common.rb, line 120
def process_id
  (@value & 0x1F000) >> 12
end
timestamp() click to toggle source
# File lib/discorb/common.rb, line 112
def timestamp
  Time.at(((@value >> 22) + 1_420_070_400_000) / 1000)
end
to_i() click to toggle source

Integerize snowflake.

@return [Integer] Integerized snowflake.

# File lib/discorb/common.rb, line 83
def to_i
  @value.to_i
end
to_s() click to toggle source

Stringify snowflake.

@return [String] Stringified snowflake.

# File lib/discorb/common.rb, line 72
def to_s
  @value.to_s
end
Also aliased as: to_str
to_str()
Alias for: to_s
worker_id() click to toggle source
# File lib/discorb/common.rb, line 116
def worker_id
  (@value & 0x3E0000) >> 17
end