Class: RubyCord::Component
- Inherits:
-
Object
- Object
- RubyCord::Component
- Defined in:
- lib/rubycord/component.rb,
lib/rubycord/component/button.rb,
lib/rubycord/component/text_input.rb,
lib/rubycord/component/select_menu.rb
Overview
Represents a select menu component.
Direct Known Subclasses
Defined Under Namespace
Classes: Button, SelectMenu, TextInput
Class Method Summary collapse
-
.from_hash(data) ⇒ Component
Create a new component from hash data.
-
.to_payload(components) ⇒ Array<Hash>
Convert components to a hash.
Instance Method Summary collapse
Class Method Details
.from_hash(data) ⇒ Component
Create a new component from hash data.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubycord/component.rb', line 22 def from_hash(data) case data[:type] when 2 Button when 3 SelectMenu when 4 TextInput end.from_hash(data) end |
.to_payload(components) ⇒ Array<Hash>
Convert components to a hash.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubycord/component.rb', line 40 def to_payload(components) tmp_components = [] tmp_row = [] components.each do |c| case c when Array tmp_components << tmp_row tmp_row = [] tmp_components << c when Component::SelectMenu, Component::TextInput tmp_components << tmp_row tmp_row = [] tmp_components << [c] else tmp_row << c end end tmp_components << tmp_row tmp_components .filter { |c| c.length.positive? } .map { |c| { type: 1, components: c.map(&:to_hash) } } end |
Instance Method Details
#inspect ⇒ Object
9 10 11 |
# File 'lib/rubycord/component.rb', line 9 def inspect "#<#{self.class}>" end |