Class: RubyCord::Component::Button
- Inherits:
-
RubyCord::Component
- Object
- RubyCord::Component
- RubyCord::Component::Button
- Defined in:
- lib/rubycord/component/button.rb
Instance Attribute Summary collapse
-
#custom_id ⇒ String
The custom ID of the button.
-
#disabled ⇒ Boolean
(also: #disabled?)
Whether the button is disabled.
-
#emoji ⇒ RubyCord::Emoji
The emoji of the button.
-
#label ⇒ String
The label of the button.
-
#style ⇒ :primary, ...
The style of the button.
-
#url ⇒ String
The URL of the button.
Class Method Summary collapse
-
.from_hash(data) ⇒ RubyCord::Component::Button
Creates a new button from a hash.
Instance Method Summary collapse
-
#initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false) ⇒ Button
constructor
Initialize a new button.
-
#inspect ⇒ String
Object class and attributes.
-
#to_hash ⇒ Hash
Converts the button to a hash.
Methods inherited from RubyCord::Component
Constructor Details
#initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false) ⇒ Button
Initialize a new button.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubycord/component/button.rb', line 39 def initialize( label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false ) @label = label @style = style @emoji = emoji @custom_id = custom_id @url = url @disabled = disabled end |
Instance Attribute Details
#custom_id ⇒ String
Returns The custom ID of the button.
Won't be used if the style is :link
.
17 18 19 |
# File 'lib/rubycord/component/button.rb', line 17 def custom_id @custom_id end |
#disabled ⇒ Boolean Also known as: disabled?
Returns Whether the button is disabled.
22 23 24 |
# File 'lib/rubycord/component/button.rb', line 22 def disabled @disabled end |
#emoji ⇒ RubyCord::Emoji
Returns The emoji of the button.
14 15 16 |
# File 'lib/rubycord/component/button.rb', line 14 def emoji @emoji end |
#label ⇒ String
Returns The label of the button.
10 11 12 |
# File 'lib/rubycord/component/button.rb', line 10 def label @label end |
#style ⇒ :primary, ...
Returns The style of the button.
12 13 14 |
# File 'lib/rubycord/component/button.rb', line 12 def style @style end |
#url ⇒ String
Returns The URL of the button.
Only used when the style is :link
.
20 21 22 |
# File 'lib/rubycord/component/button.rb', line 20 def url @url end |
Class Method Details
.from_hash(data) ⇒ RubyCord::Component::Button
Creates a new button from a hash.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rubycord/component/button.rb', line 97 def from_hash(data) new( data[:label], data[:style], emoji: data[:emoji], custom_id: data[:custom_id], url: data[:url], disabled: data[:disabled] ) end |
Instance Method Details
#inspect ⇒ String
Returns Object class and attributes.
85 86 87 |
# File 'lib/rubycord/component/button.rb', line 85 def inspect "#<#{self.class}: #{@custom_id || @url}>" end |
#to_hash ⇒ Hash
Converts the button to a hash.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rubycord/component/button.rb', line 62 def to_hash if @style == :link { type: 2, label: @label, style: STYLES[@style], url: @url, emoji: @emoji&.to_hash, disabled: @disabled } else { type: 2, label: @label, style: STYLES[@style], custom_id: @custom_id, emoji: @emoji&.to_hash, disabled: @disabled } end end |