Class: Discorb::SelectMenu::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/components/select_menu.rb

Overview

Represents an option of a select menu.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, value, description: nil, emoji: nil, default: false) -> Option

Initialize a new option.

Parameters:

  • label (String)

    The label of the option.

  • value (String)

    The value of the option.

  • description (String) (defaults to: nil)

    The description of the option.

  • emoji (Discorb::Emoji) (defaults to: nil)

    The emoji of the option.

  • default (Boolean) (defaults to: false)

    Whether the option is default.



101
102
103
104
105
106
107
# File 'lib/discorb/components/select_menu.rb', line 101

def initialize(label, value, description: nil, emoji: nil, default: false)
  @label = label
  @value = value
  @description = description
  @emoji = emoji
  @default = default
end

Instance Attribute Details

#default -> Boolean

Returns Whether the option is default.

Returns:

  • (Boolean)

    Whether the option is default.



91
92
93
# File 'lib/discorb/components/select_menu.rb', line 91

def default
  @default
end

#description -> String

Returns The description of the option.

Returns:

  • (String)

    The description of the option.



87
88
89
# File 'lib/discorb/components/select_menu.rb', line 87

def description
  @description
end

#emoji -> Discorb::Emoji

Returns The emoji of the option.

Returns:



89
90
91
# File 'lib/discorb/components/select_menu.rb', line 89

def emoji
  @emoji
end

#label -> String

Returns The label of the option.

Returns:

  • (String)

    The label of the option.



83
84
85
# File 'lib/discorb/components/select_menu.rb', line 83

def label
  @label
end

#value -> String

Returns The value of the option.

Returns:

  • (String)

    The value of the option.



85
86
87
# File 'lib/discorb/components/select_menu.rb', line 85

def value
  @value
end

Class Method Details

.from_hash(data) -> Discorb::SelectMenu::Option

Creates a new option from a hash.

Parameters:

  • data (Hash)

    A hash representing the option.

Returns:



137
138
139
# File 'lib/discorb/components/select_menu.rb', line 137

def from_hash(data)
  new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default])
end

Instance Method Details

#inspect -> Object



125
126
127
# File 'lib/discorb/components/select_menu.rb', line 125

def inspect
  "#<#{self.class} #{@label}: #{@value}>"
end

#to_hash -> Hash

Converts the option to a hash.

Returns:

  • (Hash)

    Hash representation of the option.

See Also:



115
116
117
118
119
120
121
122
123
# File 'lib/discorb/components/select_menu.rb', line 115

def to_hash
  {
    label: @label,
    value: @value,
    description: @description,
    emoji: @emoji&.to_hash,
    default: @default,
  }
end