Class: RubyCord::Component::SelectMenu

Inherits:
RubyCord::Component show all
Defined in:
lib/rubycord/component/select_menu.rb

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RubyCord::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<RubyCord::Component::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.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubycord/component/select_menu.rb', line 30

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.



10
11
12
# File 'lib/rubycord/component/select_menu.rb', line 10

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.



18
19
20
# File 'lib/rubycord/component/select_menu.rb', line 18

def disabled
  @disabled
end

#max_valuesInteger

Returns The maximum number of values.

Returns:

  • (Integer)

    The maximum number of values.



16
17
18
# File 'lib/rubycord/component/select_menu.rb', line 16

def max_values
  @max_values
end

#min_valuesInteger

Returns The minimum number of values.

Returns:

  • (Integer)

    The minimum number of values.



14
15
16
# File 'lib/rubycord/component/select_menu.rb', line 14

def min_values
  @min_values
end

#optionsArray<SelectMenu::Option>

Returns The options of the select menu.

Returns:



12
13
14
# File 'lib/rubycord/component/select_menu.rb', line 12

def options
  @options
end

Class Method Details

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

Creates a new select menu from a hash.

Parameters:

  • data (Hash)

    The hash to create the select menu from.

Returns:



76
77
78
79
80
81
82
83
84
# File 'lib/rubycord/component/select_menu.rb', line 76

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

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



64
65
66
# File 'lib/rubycord/component/select_menu.rb', line 64

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:



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rubycord/component/select_menu.rb', line 51

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