Sha256: 5bfca5923e385014c3ca34625c580289561cab04857b6bc25edb1a5f1a2ca165

Contents?: true

Size: 943 Bytes

Versions: 39

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

module Discorb
  #
  # Represents an activity for Gateway Command.
  #
  class Activity
    @types = {
      playing: 0,
      streaming: 1,
      listening: 2,
      watching: 3,
      competing: 5,
    }.freeze

    #
    # Initializes a new Activity.
    #
    # @param [String] name The name of the activity.
    # @param [:playing, :streaming, :listening, :watching, :competing] type The type of activity.
    # @param [String] url The URL of the activity.
    #
    def initialize(name, type = :playing, url = nil)
      @name = name
      @type = self.class.types[type]
      @url = url
    end

    #
    # Converts the activity to a hash.
    #
    # @return [Hash] A hash representation of the activity.
    #
    def to_hash
      {
        name: @name,
        type: @type,
        url: @url,
      }
    end

    class << self
      # @!visibility private
      attr_reader :types
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
discorb-0.9.3 lib/discorb/gateway_requests.rb
discorb-0.9.1 lib/discorb/gateway_requests.rb
discorb-0.9.0 lib/discorb/gateway_requests.rb
discorb-0.8.2 lib/discorb/gateway_requests.rb
discorb-0.8.1 lib/discorb/gateway_requests.rb
discorb-0.8.0 lib/discorb/gateway_requests.rb
discorb-0.7.6 lib/discorb/gateway_requests.rb
discorb-0.7.3 lib/discorb/gateway_requests.rb
discorb-0.7.2 lib/discorb/gateway_requests.rb
discorb-0.7.1 lib/discorb/gateway_requests.rb
discorb-0.7.0 lib/discorb/gateway_requests.rb
discorb-0.6.1 lib/discorb/gateway_requests.rb
discorb-0.6.0 lib/discorb/gateway_requests.rb
discorb-0.5.6 lib/discorb/gateway_requests.rb
discorb-0.5.5 lib/discorb/gateway_requests.rb
discorb-0.5.4 lib/discorb/gateway_requests.rb
discorb-0.5.3 lib/discorb/gateway_requests.rb
discorb-0.5.2 lib/discorb/gateway_requests.rb
discorb-0.5.1 lib/discorb/gateway_requests.rb
discorb-0.5.0 lib/discorb/gateway_requests.rb