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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/discorb/components/text_input.rb', line 40 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.
14 15 16 |
# File 'lib/discorb/components/text_input.rb', line 14 def custom_id @custom_id end |
#label -> String
Returns The label of the text input.
12 13 14 |
# File 'lib/discorb/components/text_input.rb', line 12 def label @label end |
#max_length -> Integer?
Returns The maximum length of the text input.
20 21 22 |
# File 'lib/discorb/components/text_input.rb', line 20 def max_length @max_length end |
#min_length -> Integer?
Returns The minimum length of the text input.
18 19 20 |
# File 'lib/discorb/components/text_input.rb', line 18 def min_length @min_length end |
#placeholder -> String?
Returns The placeholder of the text input.
26 27 28 |
# File 'lib/discorb/components/text_input.rb', line 26 def placeholder @placeholder end |
#required -> Boolean
Returns Whether the text input is required.
22 23 24 |
# File 'lib/discorb/components/text_input.rb', line 22 def required @required end |
#style -> :short, :paragraph
Returns The style of the text input.
16 17 18 |
# File 'lib/discorb/components/text_input.rb', line 16 def style @style end |
#value -> String?
Returns The prefilled value of the text input.
24 25 26 |
# File 'lib/discorb/components/text_input.rb', line 24 def value @value end |
Class Method Details
.from_hash(data) -> Discorb::TextInput
Creates a new text input from a hash.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/discorb/components/text_input.rb', line 89 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.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/discorb/components/text_input.rb', line 67 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 |