Class: Rubord::Modal
- Inherits:
-
Object
- Object
- Rubord::Modal
- Defined in:
- lib/rubord/components/modal.rb
Overview
Represents a Discord modal dialog component.
Modals are pop-up dialog windows that can contain text inputs. They’re triggered by interactions and allow for more complex user input.
Instance Attribute Summary collapse
-
#components ⇒ Array<Hash>
List of text input components.
-
#custom_id ⇒ String
Developer-defined identifier.
-
#title ⇒ String
Modal title (max 45 characters).
-
#type ⇒ Integer
Component type (always 1 for modals).
Instance Method Summary collapse
-
#add_text_input(custom_id:, label:, style: 1, min_length: nil, max_length: nil, required: true, value: nil, placeholder: nil) ⇒ Rubord::Modal
Adds a text input field to the modal.
-
#initialize(custom_id:, title:) ⇒ Modal
constructor
Creates a new modal dialog.
-
#to_h ⇒ Hash
Converts the modal to a Discord API-compatible hash.
Constructor Details
#initialize(custom_id:, title:) ⇒ Modal
Creates a new modal dialog.
46 47 48 49 50 51 |
# File 'lib/rubord/components/modal.rb', line 46 def initialize(custom_id:, title:) @type = 1 @custom_id = custom_id @title = title @components = [] end |
Instance Attribute Details
#components ⇒ Array<Hash>
Returns List of text input components.
34 35 36 |
# File 'lib/rubord/components/modal.rb', line 34 def components @components end |
#custom_id ⇒ String
Returns Developer-defined identifier.
28 29 30 |
# File 'lib/rubord/components/modal.rb', line 28 def custom_id @custom_id end |
#title ⇒ String
Returns Modal title (max 45 characters).
31 32 33 |
# File 'lib/rubord/components/modal.rb', line 31 def title @title end |
#type ⇒ Integer
Returns Component type (always 1 for modals).
25 26 27 |
# File 'lib/rubord/components/modal.rb', line 25 def type @type end |
Instance Method Details
#add_text_input(custom_id:, label:, style: 1, min_length: nil, max_length: nil, required: true, value: nil, placeholder: nil) ⇒ Rubord::Modal
Adds a text input field to the modal.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubord/components/modal.rb', line 86 def add_text_input(custom_id:, label:, style: 1, min_length: nil, max_length: nil, required: true, value: nil, placeholder: nil) @components << { type: 4, custom_id: custom_id, style: style, label: label, min_length: min_length, max_length: max_length, required: required, value: value, placeholder: placeholder }.compact self end |
#to_h ⇒ Hash
Converts the modal to a Discord API-compatible hash.
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rubord/components/modal.rb', line 109 def to_h { type: @type, custom_id: @custom_id, title: @title, components: [ { type: 1, components: @components } ] } end |