Class: Lobster::UserStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/lobster/user_status.rb

Overview

Information about a user's current status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ UserStatus

Creates a new profile status.

Parameters:

  • id (Uuid)

    Unique ID of the user the status is for.



101
102
103
104
105
106
# File 'lib/lobster/user_status.rb', line 101

def initialize(id)
  fail ArgumentError unless id.is_a?(Uuid)

  @id   = id
  @idle = false
end

Instance Attribute Details

#activeTime

Last time the user was active. This can be treated as the last time the user interacted with the server in some manor that indicates the user physically did something (was not automatic).

Returns:

  • (Time)

    Date and time of last activity.



18
# File 'lib/lobster/user_status.rb', line 18

attr_type_accessor :active, Time

#idUuid (readonly)

Unique ID of the user this status refers to.

Returns:



11
12
13
# File 'lib/lobster/user_status.rb', line 11

def id
  @id
end

#messageString

Additional information the user may set about their status. This will be information about the game the user is playing when #state is :game.

Returns:

  • (String)

    Additional status information.



97
# File 'lib/lobster/user_status.rb', line 97

attr_type_accessor :message, String

#stateSymbol

Current state of the user. :online means the user is connected to the server. :offline means the opposite - the user isn't connected to the server. :game indicates the user is online and currently playing a game. :game overrides :away. :away means the user is online and has set their status to away (AFK). :busy means the user is online and has set their status to busy (do not disturb). :busy overrides :game and :away.

Returns:

  • (Symbol)

    One of: :online, :offline, :game, :busy, or :away.



29
30
31
# File 'lib/lobster/user_status.rb', line 29

def state
  @state
end

Instance Method Details

#active?Boolean

Indicates whether the user has been active recently. This is the opposite of #idle?.

Returns:

  • (Boolean)


76
77
78
# File 'lib/lobster/user_status.rb', line 76

def active?
  !@idle
end

#away?Boolean

Indicates whether the user has set their status to away (AFK). This will be true when #state is :away.

Returns:

  • (Boolean)


64
65
66
# File 'lib/lobster/user_status.rb', line 64

def away?
  @state == :away
end

#busy?Boolean

Indicates whether the user has set their status to busy (do not disturb). This will be true when #state is :busy.

Returns:

  • (Boolean)


58
59
60
# File 'lib/lobster/user_status.rb', line 58

def busy?
  @state == :busy
end

#idle=(flag) ⇒ nil

Sets the idle state of the user.

Parameters:

  • flag (Boolean)

    true if the user is now idle or false if they're now active.

Returns:

  • (nil)


89
90
91
# File 'lib/lobster/user_status.rb', line 89

def idle=(flag)
  @idle = !!flag # Force to boolean.
end

#idle?Boolean

Indicates whether the user has been inactive for a period of time. This is the opposite of #active?.

Returns:

  • (Boolean)


82
83
84
# File 'lib/lobster/user_status.rb', line 82

def idle?
  @idle
end

#in_game?Boolean

Indicates whether the user is currently in a game. This will be true when #state is :game.

Returns:

  • (Boolean)


70
71
72
# File 'lib/lobster/user_status.rb', line 70

def in_game?
  @state == :game
end

#offline?Boolean

Indicates whether the user is not connected to the server. This is effectively the opposite of #online?. It will only be true when #state is :offline.

Returns:

  • (Boolean)


52
53
54
# File 'lib/lobster/user_status.rb', line 52

def offline?
  @state == :offline
end

#online?Boolean

Indicates whether the user is connected to the server or not. This will be true when #state is anything but :offline.

Returns:

  • (Boolean)


45
46
47
# File 'lib/lobster/user_status.rb', line 45

def online?
  @state != :offline
end