Module: MijDiscord::Data::IDObject

Included in:
Application, Channel, Emoji, InviteChannel, InviteServer, Message, Overwrite, Role, Server, User, Webhook
Defined in:
lib/mij-discord/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly) Also known as: to_id

Returns the value of attribute id.



9
10
11
# File 'lib/mij-discord/data.rb', line 9

def id
  @id
end

Class Method Details

.synthesize(time) ⇒ Object



26
27
28
29
# File 'lib/mij-discord/data.rb', line 26

def self.synthesize(time)
  ms = (time.to_f * 1000).to_i
  (ms - DISCORD_EPOCH) << 22
end

.timestamp(id) ⇒ Object



31
32
33
34
# File 'lib/mij-discord/data.rb', line 31

def self.timestamp(id)
  ms = (id >> 22) + DISCORD_EPOCH
  Time.at(ms / 1000.0).utc
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



16
17
18
# File 'lib/mij-discord/data.rb', line 16

def ==(other)
  @id == (other.respond_to?(:to_id) ? other.to_id : other)
end

#creation_timeObject



22
23
24
# File 'lib/mij-discord/data.rb', line 22

def creation_time
  IDObject.timestamp(@id)
end

#hashObject



12
13
14
# File 'lib/mij-discord/data.rb', line 12

def hash
  @id.hash
end