Class: Discorb::SelectMenu
- Defined in:
- lib/discorb/components/select_menu.rb
Overview
Represents a select menu component.
Defined Under Namespace
Classes: Option
Instance Attribute Summary collapse
-
#custom_id ⇒ String
The custom ID of the select menu.
-
#disabled ⇒ Boolean
(also: #disabled?)
Whether the select menu is disabled.
-
#max_values ⇒ Integer
The maximum number of values.
-
#min_values ⇒ Integer
The minimum number of values.
-
#options ⇒ Array<SelectMenu::Option>
The options of the select menu.
Class Method Summary collapse
-
.from_hash(data) ⇒ Discorb::SelectMenu
Creates a new select menu from a hash.
Instance Method Summary collapse
-
#initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) ⇒ SelectMenu
constructor
Initialize a new select menu.
- #inspect ⇒ Object
-
#to_hash ⇒ Hash
Converts the select menu to a hash.
Methods inherited from Component
Constructor Details
#initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) ⇒ SelectMenu
Initialize a new select menu.
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, , placeholder: nil, min_values: 1, max_values: 1 ) @custom_id = custom_id @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.
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.
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.
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.
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.
11 12 13 |
# File 'lib/discorb/components/select_menu.rb', line 11 def @options end |
Class Method Details
.from_hash(data) ⇒ Discorb::SelectMenu
Creates a new select menu from a hash.
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
#inspect ⇒ Object
62 63 64 |
# File 'lib/discorb/components/select_menu.rb', line 62 def inspect "#<#{self.class}: #{@custom_id}>" end |
#to_hash ⇒ Hash
Converts the select menu to a hash.
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 |