Class: RubyCord::Activity
- Inherits:
-
Object
- Object
- RubyCord::Activity
- Defined in:
- lib/rubycord/gateway_requests.rb
Overview
Represents an activity for Gateway Command.
Instance Attribute Summary collapse
-
#text ⇒ String
readonly
The text of the activity.
-
#type ⇒ :playing, ...
readonly
The type of the activity.
-
#url ⇒ String
readonly
The URL of the activity.
Instance Method Summary collapse
-
#initialize(text, type = :playing, url: nil) ⇒ Activity
constructor
Initializes a new Activity.
- #inspect ⇒ Object
-
#to_hash ⇒ Hash
Converts the activity to a hash.
Constructor Details
#initialize(text, type = :playing, url: nil) ⇒ Activity
Initializes a new Activity.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubycord/gateway_requests.rb', line 34 def initialize(text, type = :playing, url: nil) @text = text @type = ( if TYPES.key?(type) TYPES[type] else raise(ArgumentError, "invalid activity type: #{type}") end ) @url = url end |
Instance Attribute Details
#text ⇒ String (readonly)
Returns The text of the activity.
10 11 12 |
# File 'lib/rubycord/gateway_requests.rb', line 10 def text @text end |
#type ⇒ :playing, ... (readonly)
Returns The type of the activity.
12 13 14 |
# File 'lib/rubycord/gateway_requests.rb', line 12 def type @type end |
#url ⇒ String (readonly)
Returns The URL of the activity.
14 15 16 |
# File 'lib/rubycord/gateway_requests.rb', line 14 def url @url end |
Instance Method Details
#inspect ⇒ Object
60 61 62 |
# File 'lib/rubycord/gateway_requests.rb', line 60 def inspect "#<#{self.class} @type=#{@type}>" end |
#to_hash ⇒ Hash
Converts the activity to a hash.
52 53 54 55 56 57 58 |
# File 'lib/rubycord/gateway_requests.rb', line 52 def to_hash if @type == :custom { state: @text, type: @type, url: @url } else { name: @text, type: @type, url: @url } end end |