Class: RubyCord::Component::SelectMenu::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycord/component/select_menu.rb

Overview

Represents an option of a select menu.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, value, description: nil, emoji: nil, default: false) ⇒ Option

Initialize a new option.

Parameters:

  • label (String)

    The label of the option.

  • value (String)

    The value of the option.

  • description (String) (defaults to: nil)

    The description of the option.

  • emoji (RubyCord::Emoji) (defaults to: nil)

    The emoji of the option.

  • default (Boolean) (defaults to: false)

    Whether the option is default.



110
111
112
113
114
115
116
# File 'lib/rubycord/component/select_menu.rb', line 110

def initialize(label, value, description: nil, emoji: nil, default: false)
  @label = label
  @value = value
  @description = description
  @emoji = emoji
  @default = default
end

Instance Attribute Details

#defaultBoolean

Returns Whether the option is default.

Returns:

  • (Boolean)

    Whether the option is default.



100
101
102
# File 'lib/rubycord/component/select_menu.rb', line 100

def default
  @default
end

#descriptionString

Returns The description of the option.

Returns:

  • (String)

    The description of the option.



96
97
98
# File 'lib/rubycord/component/select_menu.rb', line 96

def description
  @description
end

#emojiRubyCord::Emoji

Returns The emoji of the option.

Returns:



98
99
100
# File 'lib/rubycord/component/select_menu.rb', line 98

def emoji
  @emoji
end

#labelString

Returns The label of the option.

Returns:

  • (String)

    The label of the option.



92
93
94
# File 'lib/rubycord/component/select_menu.rb', line 92

def label
  @label
end

#valueString

Returns The value of the option.

Returns:

  • (String)

    The value of the option.



94
95
96
# File 'lib/rubycord/component/select_menu.rb', line 94

def value
  @value
end

Class Method Details

.from_hash(data) ⇒ RubyCord::Component::SelectMenu::Option

Creates a new option from a hash.

Parameters:

  • data (Hash)

    A hash representing the option.

Returns:



148
149
150
151
152
153
154
155
156
# File 'lib/rubycord/component/select_menu.rb', line 148

def from_hash(data)
  new(
    data[:label],
    data[:value],
    description: data[:description],
    emoji: data[:emoji],
    default: data[:default]
  )
end

Instance Method Details

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



136
137
138
# File 'lib/rubycord/component/select_menu.rb', line 136

def inspect
  "#<#{self.class} #{@label}: #{@value}>"
end

#to_hashHash

Converts the option to a hash.

Returns:

  • (Hash)

    Hash representation of the option.

See Also:



125
126
127
128
129
130
131
132
133
# File 'lib/rubycord/component/select_menu.rb', line 125

def to_hash
  {
    label: @label,
    value: @value,
    description: @description,
    emoji: @emoji&.to_hash,
    default: @default
  }
end