Class: Rubord::Emoji

Inherits:
Object
  • Object
show all
Defined in:
lib/rubord/models/emoji.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client) ⇒ Emoji

Returns a new instance of Emoji.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubord/models/emoji.rb', line 12

def initialize(data, client)
  @client        = client
  @id            = data["id"]
  @name          = data["name"]
  @roles         = data["roles"] || []
  @require_colons = data["require_colons"]
  @managed       = data["managed"]
  @animated      = data["animated"]
  @available     = data.fetch("available", true)

  if data["user"]
    @user = Rubord::User.new(data["user"])
    client.users.set(@user.id, @user)
  end
end

Instance Attribute Details

#animatedObject (readonly)

Returns the value of attribute animated.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def animated
  @animated
end

#availableObject (readonly)

Returns the value of attribute available.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def available
  @available
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def id
  @id
end

#managedObject (readonly)

Returns the value of attribute managed.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def managed
  @managed
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def name
  @name
end

#require_colonsObject (readonly)

Returns the value of attribute require_colons.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def require_colons
  @require_colons
end

#rolesObject (readonly)

Returns the value of attribute roles.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def roles
  @roles
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/rubord/models/emoji.rb', line 3

def user
  @user
end

Instance Method Details

#inspectObject



50
51
52
# File 'lib/rubord/models/emoji.rb', line 50

def inspect
  "#<Rubord::Emoji name=#{@name} id=#{@id}"
end

#to_discordObject



28
29
30
31
32
33
34
# File 'lib/rubord/models/emoji.rb', line 28

def to_discord
  if animated
    "<a:#{@name}:#{@id}>"
  else
    "<:#{@name}:#{@id}>"
  end
end

#to_hObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubord/models/emoji.rb', line 36

def to_h
  {
    id: @id,
    name: @name,
    roles: @roles,
    format: to_discord,
    user: @user ? @user.to_h : nil,
    require_colons: @require_colons,
    managed: @managed,
    animated: @animated,
    available: @available
  }
end