Class: OnyxCord::Webhooks::View::ContainerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/webhooks/view/container_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, color: nil, colour: nil, spoiler: false) {|builder| ... } ⇒ ContainerBuilder

Create a container component.

Parameters:

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the container component.

  • colour (Array, Integer, String, ColourRGB, nil) (defaults to: nil)

    The accent colour of the container component. This argument can be passed via the American spelling (color:) as well.

  • spoiler (true, false) (defaults to: false)

    Whether or not to apply a spoiler label to the container component.

Yield Parameters:



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.

Parameters:

  • colour (Array, Integer, String, ColourRGB, nil)

    The accent colour of the container component, or nil to clear the accent colour.



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

#fileObject 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

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

#rowObject

Add a row component to the container.

See Also:

  • RowBuilder#initialize


22
23
24
# File 'lib/onyxcord/webhooks/view/container_builder.rb', line 22

def row(...)
  @components << RowBuilder.new(...)
end

#sectionObject

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

#separatorObject

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_displayObject

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