Class: Discorb::Activity

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

Overview

Represents an activity for Gateway Command.

Instance Method Summary collapse

Constructor Details

#initialize(name, type = :playing, url = nil) -> Activity

Initializes a new Activity.

Parameters:

  • name (String)

    The name of the activity.

  • type (:playing, :streaming, :listening, :watching, :competing) (defaults to: :playing)

    The type of activity.

  • url (String) (defaults to: nil)

    The URL of the activity.



25
26
27
28
29
# File 'lib/discorb/gateway_requests.rb', line 25

def initialize(name, type = :playing, url = nil)
  @name = name
  @type = TYPES[type] or raise ArgumentError, "Invalid activity type: #{type}"
  @url = url
end

Instance Method Details

#inspect -> Object



44
45
46
# File 'lib/discorb/gateway_requests.rb', line 44

def inspect
  "#<#{self.class} @type=#{@type}>"
end

#to_hash -> Hash

Converts the activity to a hash.

Returns:

  • (Hash)

    A hash representation of the activity.



36
37
38
39
40
41
42
# File 'lib/discorb/gateway_requests.rb', line 36

def to_hash
  {
    name: @name,
    type: @type,
    url: @url,
  }
end