class Discorb::SelectMenu::Option

Represents an option of a select menu.

Attributes

default[RW]

@return [Boolean] Whether the option is default.

description[RW]

@return [String] The description of the option.

emoji[RW]

@return [Discorb::Emoji] The emoji of the option.

label[RW]

@return [String] The label of the option.

value[RW]

@return [String] The value of the option.

Public Class Methods

from_hash(data) click to toggle source

Creates a new option from a hash.

@param [Hash] data A hash representing the option.

@return [Discorb::SelectMenu::Option] A new option.

# File lib/discorb/components.rb, line 265
def from_hash(data)
  new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default])
end
new(label, value, description: nil, emoji: nil, default: false) click to toggle source

Initialize a new option.

@param [String] label The label of the option. @param [String] value The value of the option. @param [String] description The description of the option. @param [Discorb::Emoji] emoji The emoji of the option. @param [Boolean] default Whether the option is default.

# File lib/discorb/components.rb, line 215
def initialize(label, value, description: nil, emoji: nil, default: false)
  @label = label
  @value = value
  @description = description
  @emoji = emoji
  @default = default
end

Public Instance Methods

hash_emoji(emoji) click to toggle source

@!visibility private

# File lib/discorb/components.rb, line 240
def hash_emoji(emoji)
  case emoji
  when UnicodeEmoji
    {
      id: nil,
      name: emoji.to_s,
      animated: false,
    }
  when CustomEmoji
    {
      id: emoji.id,
      name: emoji.name,
      animated: emoji.animated?,
    }
  end
end
to_hash() click to toggle source

Converts the option to a hash.

@see discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure Official Discord API docs @return [Hash] Hash representation of the option.

# File lib/discorb/components.rb, line 229
def to_hash
  {
    label: @label,
    value: @value,
    description: @description,
    emoji: hash_emoji(@emoji),
    default: @default,
  }
end