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.



108
109
110
111
112
113
114
# File 'lib/discorb/components/select_menu.rb', line 108

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

Instance Attribute Details

#defaultBoolean



98
99
100
# File 'lib/discorb/components/select_menu.rb', line 98

def default
  @default
end

#descriptionString



94
95
96
# File 'lib/discorb/components/select_menu.rb', line 94

def description
  @description
end

#emojiDiscorb::Emoji



96
97
98
# File 'lib/discorb/components/select_menu.rb', line 96

def emoji
  @emoji
end

#labelString



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

def label
  @label
end

#valueString



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

def value
  @value
end

Class Method Details

.from_hash(data) ⇒ Discorb::SelectMenu::Option

Creates a new option from a hash.



145
146
147
148
149
150
151
152
153
# File 'lib/discorb/components/select_menu.rb', line 145

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

Instance Method Details

#inspectObject



133
134
135
# File 'lib/discorb/components/select_menu.rb', line 133

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

#to_hashHash

Converts the option to a hash.



123
124
125
126
127
128
129
130
131
# File 'lib/discorb/components/select_menu.rb', line 123

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