Class: Discorb::Activity

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

Overview

Represents an activity for Gateway Command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, type = :playing, url: nil) ⇒ Activity

Initializes a new Activity.

Parameters:

  • text (String)

    The text of the activity.

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

    The type of activity.

  • url (String) (defaults to: nil)

    The URL of the activity.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/discorb/gateway_requests.rb', line 33

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

#textString (readonly)

Returns The text of the activity.

Returns:

  • (String)

    The text of the activity.



9
10
11
# File 'lib/discorb/gateway_requests.rb', line 9

def text
  @text
end

#type:playing, ... (readonly)

Returns The type of the activity.

Returns:

  • (:playing, :streaming, :listening, :watching, :custom, :competing)

    The type of the activity.



11
12
13
# File 'lib/discorb/gateway_requests.rb', line 11

def type
  @type
end

#urlString (readonly)

Returns The URL of the activity.

Returns:

  • (String)

    The URL of the activity.



13
14
15
# File 'lib/discorb/gateway_requests.rb', line 13

def url
  @url
end

Instance Method Details

#inspectObject



59
60
61
# File 'lib/discorb/gateway_requests.rb', line 59

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

#to_hashHash

Converts the activity to a hash.

Returns:

  • (Hash)

    A hash representation of the activity.



51
52
53
54
55
56
57
# File 'lib/discorb/gateway_requests.rb', line 51

def to_hash
  if @type == :custom
    { state: @text, type: @type, url: @url }
  else
    { name: @text, type: @type, url: @url }
  end
end