Class: Discorb::SelectMenu

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

Overview

Represents a select menu component.

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/discorb/components/select_menu.rb', line 29

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_idString

Returns The custom ID of the select menu.

Returns:

  • (String)

    The custom ID of the select menu.



9
10
11
# File 'lib/discorb/components/select_menu.rb', line 9

def custom_id
  @custom_id
end

#disabledBoolean Also known as: disabled?

Returns Whether the select menu is disabled.

Returns:

  • (Boolean)

    Whether the select menu is disabled.



17
18
19
# File 'lib/discorb/components/select_menu.rb', line 17

def disabled
  @disabled
end

#max_valuesInteger

Returns The maximum number of values.

Returns:

  • (Integer)

    The maximum number of values.



15
16
17
# File 'lib/discorb/components/select_menu.rb', line 15

def max_values
  @max_values
end

#min_valuesInteger

Returns The minimum number of values.

Returns:

  • (Integer)

    The minimum number of values.



13
14
15
# File 'lib/discorb/components/select_menu.rb', line 13

def min_values
  @min_values
end

#optionsArray<SelectMenu::Option>

Returns The options of the select menu.

Returns:



11
12
13
# File 'lib/discorb/components/select_menu.rb', line 11

def options
  @options
end

Class Method Details

.from_hash(data) ⇒ Discorb::SelectMenu

Creates a new select menu from a hash.

Parameters:

  • data (Hash)

    The hash to create the select menu from.

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/discorb/components/select_menu.rb', line 74

def from_hash(data)
  new(
    data[:custom_id],
    data[:options].map { |o| SelectMenu::Option.from_hash(o) },
    placeholder: data[:placeholder],
    min_values: data[:min_values],
    max_values: data[:max_values]
  )
end

Instance Method Details

#inspectObject



62
63
64
# File 'lib/discorb/components/select_menu.rb', line 62

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

#to_hashHash

Converts the select menu to a hash.

Returns:

  • (Hash)

    A hash representation of the select menu.

See Also:



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/discorb/components/select_menu.rb', line 50

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