Class: OnyxCord::Webhooks::View::ContainerBuilder
- Inherits:
-
Object
- Object
- OnyxCord::Webhooks::View::ContainerBuilder
- Defined in:
- lib/onyxcord/webhooks/view/container_builder.rb
Instance Method Summary collapse
-
#colour=(colour) ⇒ Object
(also: #color=)
Set the color of the container.
-
#file ⇒ Object
(also: #file_display)
Add a file component to the container.
-
#initialize(id: nil, color: nil, colour: nil, spoiler: false) {|builder| ... } ⇒ ContainerBuilder
constructor
Create a container component.
-
#media_gallery(*items, id: nil, &block) ⇒ Object
Add a media gallery component to the container.
-
#row ⇒ Object
Add a row component to the container.
-
#section ⇒ Object
Add a section component to the container.
-
#separator ⇒ Object
Add a separator component to the container.
-
#text_display ⇒ Object
Add a text display component to the container.
Constructor Details
#initialize(id: nil, color: nil, colour: nil, spoiler: false) {|builder| ... } ⇒ ContainerBuilder
Create a container component.
11 12 13 14 15 16 17 18 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 11 def initialize(id: nil, color: nil, colour: nil, spoiler: false) @id = id @spoiler = spoiler @components = [] self.colour = (colour || color) yield self if block_given? end |
Instance Method Details
#colour=(colour) ⇒ Object Also known as: color=
Set the color of the container.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 60 def colour=(colour) @colour = case colour when Array raise ArgumentError, 'Colour array must have exactly 3 elements (R, G, B)' unless colour.size == 3 r, g, b = colour raise ArgumentError, 'RGB values must be between 0 and 255' unless [r, g, b].all? { |v| v.is_a?(Integer) && v.between?(0, 255) } (r << 16) | (g << 8) | b when String colour.delete('#').to_i(16) else colour&.to_i end end |
#file ⇒ Object Also known as: file_display
Add a file component to the container.
28 29 30 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 28 def file(...) @components << FileBuilder.new(...) end |
#media_gallery(*items, id: nil, &block) ⇒ Object
Add a media gallery component to the container.
54 55 56 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 54 def media_gallery(*items, id: nil, &block) @components << MediaGalleryBuilder.new(*items, id: id, &block) end |
#row ⇒ Object
Add a row component to the container.
22 23 24 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 22 def row(...) @components << RowBuilder.new(...) end |
#section ⇒ Object
Add a section component to the container.
36 37 38 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 36 def section(...) @components << SectionBuilder.new(...) end |
#separator ⇒ Object
Add a separator component to the container.
42 43 44 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 42 def separator(...) @components << SeparatorBuilder.new(...) end |
#text_display ⇒ Object
Add a text display component to the container.
48 49 50 |
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 48 def text_display(...) @components << TextDisplayBuilder.new(...) end |