Class: DiscordRDA::Components::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/discord_rda/interactions/components.rb

Overview

Builder class for constructing component rows

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



371
372
373
374
# File 'lib/discord_rda/interactions/components.rb', line 371

def initialize
  @rows = []
  @current_row = nil
end

Instance Method Details

#button(**kwargs) ⇒ self

Add a button to current row

Parameters:

  • kwargs (Hash)

    Button options

Returns:

  • (self)


390
391
392
393
394
# File 'lib/discord_rda/interactions/components.rb', line 390

def button(**kwargs)
  ensure_row
  @current_row.add(Button.new(**kwargs))
  self
end

#channel_select(**kwargs) ⇒ self

Add a channel select to current row

Parameters:

  • kwargs (Hash)

    Select options

Returns:

  • (self)


435
436
437
438
439
# File 'lib/discord_rda/interactions/components.rb', line 435

def channel_select(**kwargs)
  ensure_row
  @current_row.add(ChannelSelect.new(**kwargs))
  self
end

#mentionable_select(**kwargs) ⇒ self

Add a mentionable select to current row

Parameters:

  • kwargs (Hash)

    Select options

Returns:

  • (self)


426
427
428
429
430
# File 'lib/discord_rda/interactions/components.rb', line 426

def mentionable_select(**kwargs)
  ensure_row
  @current_row.add(MentionableSelect.new(**kwargs))
  self
end

#role_select(**kwargs) ⇒ self

Add a role select to current row

Parameters:

  • kwargs (Hash)

    Select options

Returns:

  • (self)


417
418
419
420
421
# File 'lib/discord_rda/interactions/components.rb', line 417

def role_select(**kwargs)
  ensure_row
  @current_row.add(RoleSelect.new(**kwargs))
  self
end

#row {|ActionRow| ... } ⇒ self

Start a new action row

Yields:

Returns:

  • (self)


379
380
381
382
383
384
385
# File 'lib/discord_rda/interactions/components.rb', line 379

def row
  @current_row = ActionRow.new
  yield @current_row if block_given?
  @rows << @current_row
  @current_row = nil
  self
end

#string_select(**kwargs) ⇒ self

Add a string select to current row

Parameters:

  • kwargs (Hash)

    Select options

Returns:

  • (self)


399
400
401
402
403
# File 'lib/discord_rda/interactions/components.rb', line 399

def string_select(**kwargs)
  ensure_row
  @current_row.add(StringSelect.new(**kwargs))
  self
end

#to_aArray<Hash>

Convert to array of component hashes

Returns:

  • (Array<Hash>)

    Components array



443
444
445
# File 'lib/discord_rda/interactions/components.rb', line 443

def to_a
  @rows.map(&:to_h)
end

#user_select(**kwargs) ⇒ self

Add a user select to current row

Parameters:

  • kwargs (Hash)

    Select options

Returns:

  • (self)


408
409
410
411
412
# File 'lib/discord_rda/interactions/components.rb', line 408

def user_select(**kwargs)
  ensure_row
  @current_row.add(UserSelect.new(**kwargs))
  self
end