Class: RubyCord::Component::SelectMenu
- Inherits:
-
RubyCord::Component
- Object
- RubyCord::Component
- RubyCord::Component::SelectMenu
- Defined in:
- lib/rubycord/component/select_menu.rb
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) ⇒ RubyCord::Component::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 ⇒ String
Object class and attributes.
-
#to_hash ⇒ Hash
Converts the select menu to a hash.
Methods inherited from RubyCord::Component
Constructor Details
#initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) ⇒ SelectMenu
Initialize a new select menu.
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, , 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.
10 11 12 |
# File 'lib/rubycord/component/select_menu.rb', line 10 def custom_id @custom_id end |
#disabled ⇒ Boolean Also known as: disabled?
Returns Whether the select menu is disabled.
18 19 20 |
# File 'lib/rubycord/component/select_menu.rb', line 18 def disabled @disabled end |
#max_values ⇒ Integer
Returns The maximum number of values.
16 17 18 |
# File 'lib/rubycord/component/select_menu.rb', line 16 def max_values @max_values end |
#min_values ⇒ Integer
Returns The minimum number of values.
14 15 16 |
# File 'lib/rubycord/component/select_menu.rb', line 14 def min_values @min_values end |
#options ⇒ Array<SelectMenu::Option>
Returns The options of the select menu.
12 13 14 |
# File 'lib/rubycord/component/select_menu.rb', line 12 def @options end |
Class Method Details
.from_hash(data) ⇒ RubyCord::Component::SelectMenu
Creates a new select menu from a hash.
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
#inspect ⇒ String
Returns Object class and attributes.
64 65 66 |
# File 'lib/rubycord/component/select_menu.rb', line 64 def inspect "#<#{self.class}: #{@custom_id}>" end |
#to_hash ⇒ Hash
Converts the select menu to a hash.
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 |