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
# 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_id -> String

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

#disabled -> Boolean 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_values -> Integer

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_values -> Integer

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

#options -> Array<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:



68
69
70
71
72
73
74
75
76
# File 'lib/discorb/components/select_menu.rb', line 68

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

#inspect -> Object



56
57
58
# File 'lib/discorb/components/select_menu.rb', line 56

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:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/discorb/components/select_menu.rb', line 44

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