Class: Discorb::TextInput
- Defined in:
- lib/discorb/components/text_input.rb
Overview
Represents a text input component.
Instance Attribute Summary collapse
-
#custom_id -> String
The custom id of the text input.
-
#label -> String
The label of the text input.
-
#max_length -> Integer?
The maximum length of the text input.
-
#min_length -> Integer?
The minimum length of the text input.
-
#placeholder -> String?
The placeholder of the text input.
-
#required -> Boolean
Whether the text input is required.
-
#style -> :short, :paragraph
The style of the text input.
-
#value -> String?
The prefilled value of the text input.
Class Method Summary collapse
-
.from_hash(data) -> Discorb::TextInput
Creates a new text input from a hash.
Instance Method Summary collapse
-
#initialize(label, custom_id, style, min_length: nil, max_length: nil, required: false, value: nil, placeholder: nil) -> TextInput
constructor
Initialize a new text input component.
-
#to_hash -> Hash
Converts the select menu to a hash.
Methods inherited from Component
Constructor Details
#initialize(label, custom_id, style, min_length: nil, max_length: nil, required: false, value: nil, placeholder: nil) -> TextInput
Initialize a new text input component.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/discorb/components/text_input.rb', line 43 def initialize(label, custom_id, style, min_length: nil, max_length: nil, required: false, value: nil, placeholder: nil) @label = label @custom_id = custom_id @style = style @min_length = min_length @max_length = max_length @required = required @value = value @placeholder = placeholder end |
Instance Attribute Details
#custom_id -> String
Returns The custom id of the text input.
17 18 19 |
# File 'lib/discorb/components/text_input.rb', line 17 def custom_id @custom_id end |
#label -> String
Returns The label of the text input.
15 16 17 |
# File 'lib/discorb/components/text_input.rb', line 15 def label @label end |
#max_length -> Integer?
Returns The maximum length of the text input.
23 24 25 |
# File 'lib/discorb/components/text_input.rb', line 23 def max_length @max_length end |
#min_length -> Integer?
Returns The minimum length of the text input.
21 22 23 |
# File 'lib/discorb/components/text_input.rb', line 21 def min_length @min_length end |
#placeholder -> String?
Returns The placeholder of the text input.
29 30 31 |
# File 'lib/discorb/components/text_input.rb', line 29 def placeholder @placeholder end |
#required -> Boolean
Returns Whether the text input is required.
25 26 27 |
# File 'lib/discorb/components/text_input.rb', line 25 def required @required end |
#style -> :short, :paragraph
Returns The style of the text input.
19 20 21 |
# File 'lib/discorb/components/text_input.rb', line 19 def style @style end |
#value -> String?
Returns The prefilled value of the text input.
27 28 29 |
# File 'lib/discorb/components/text_input.rb', line 27 def value @value end |
Class Method Details
.from_hash(data) -> Discorb::TextInput
Creates a new text input from a hash.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/discorb/components/text_input.rb', line 82 def from_hash(data) new( data[:label], data[:custom_id], STYLES.key(data[:style]), min_length: data[:min_length], max_length: data[:max_length], required: data[:required], value: data[:value], placeholder: data[:placeholder], ) end |
Instance Method Details
#to_hash -> Hash
Converts the select menu to a hash.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/discorb/components/text_input.rb', line 60 def to_hash { type: 4, label: @label, style: STYLES[@style], custom_id: @custom_id, min_length: @min_length, max_length: @max_length, required: @required, value: @value, placeholder: @placeholder, } end |