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