Class: Discorb::SelectMenu

Inherits:
Component show all
Defined in:
lib/discorb/components.rb

Overview

Represents a select menu component.

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

from_hash, to_payload

Constructor Details

#initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) -> SelectMenu

Initialize a new select menu.

Parameters:

  • custom_id (String, Symbol)

    Custom ID of the select menu.

  • options (Array<Discorb::SelectMenu::Option>)

    The options of the select menu.

  • placeholder (String) (defaults to: nil)

    The placeholder of the select menu.

  • min_values (Integer) (defaults to: 1)

    The minimum number of values.

  • max_values (Integer) (defaults to: 1)

    The maximum number of values.



203
204
205
206
207
208
209
# File 'lib/discorb/components.rb', line 203

def initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1)
  @custom_id = custom_id
  @options = options
  @placeholder = placeholder
  @min_values = min_values
  @max_values = max_values
end

Instance Attribute Details

#custom_id -> String

Returns The custom ID of the select menu.

Returns:

  • (String)

    The custom ID of the select menu.



183
184
185
# File 'lib/discorb/components.rb', line 183

def custom_id
  @custom_id
end

#disabled -> Boolean Also known as: disabled?

Returns Whether the select menu is disabled.

Returns:

  • (Boolean)

    Whether the select menu is disabled.



191
192
193
# File 'lib/discorb/components.rb', line 191

def disabled
  @disabled
end

#max_values -> Integer

Returns The maximum number of values.

Returns:

  • (Integer)

    The maximum number of values.



189
190
191
# File 'lib/discorb/components.rb', line 189

def max_values
  @max_values
end

#min_values -> Integer

Returns The minimum number of values.

Returns:

  • (Integer)

    The minimum number of values.



187
188
189
# File 'lib/discorb/components.rb', line 187

def min_values
  @min_values
end

#options -> Array<SelectMenu::Option>

Returns The options of the select menu.

Returns:



185
186
187
# File 'lib/discorb/components.rb', line 185

def options
  @options
end

Instance Method Details

#inspect -> Object



229
230
231
# File 'lib/discorb/components.rb', line 229

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

#to_hash -> Hash

Converts the select menu to a hash.

Returns:

  • (Hash)

    A hash representation of the select menu.

See Also:



217
218
219
220
221
222
223
224
225
226
227
# File 'lib/discorb/components.rb', line 217

def to_hash
  {
    type: 3,
    custom_id: @custom_id,
    options: @options.map(&:to_hash),
    placeholder: @placeholder,
    min_values: @min_values,
    max_values: @max_values,
    disabled: @disabled,
  }
end