class TriviaCrack::Game

Attributes

available_crowns[R]

Public: Array of available crowns that can be won by the user.

created[R]

Public: The datetime on which the game was created.

expiration_date[R]

Public: The datetime on which the game will expire.

game_status[R]

Public: The current status of the game (e.g. :active, :ended, :pending_approval).

id[R]

Public: The unique identifier of the game.

is_random[R]

Public: Boolean indicating whether the game was created with a random opponent.

language[R]

Public: The language used for the game (e.g. :en).

last_turn[R]

Public: The datetime on which the last turn was taken.

my_statistics[R]

Public: TriviaCrack::GameStatistics for the user.

my_turn[R]

Public: Boolean indicating whether it is the user's turn.

opponent[R]

Public: The TriviaCrack::User information for the opponent.

opponent_statistics[R]

Public: TriviaCrack::GameStatistics for the opponent.

questions[R]

Public: Array of questions that can be answered by the user. This array will be empty if the user is unable to play (i.e. not their turn).

round_number[R]

Public: The number of the current round.

status_version[R]

Public: The status version.

type[R]

Public: The type of the game (:normal, :duel)

unread_messages[R]

Public: Number of unread messages.

Public Class Methods

new(id:, opponent: nil, game_status: nil, language: nil, created: nil, last_turn: nil, type: nil, expiration_date: nil, my_turn: nil, round_number: nil, is_random: nil, unread_messages: nil, status_version: nil, available_crowns: nil, questions: nil, my_statistics: nil, opponent_statistics: nil) click to toggle source
# File lib/triviacrack/game.rb, line 61
def initialize(id:, opponent: nil, game_status: nil, language: nil,
               created: nil, last_turn: nil, type: nil,
               expiration_date: nil, my_turn: nil, round_number: nil,
               is_random: nil, unread_messages: nil, status_version: nil,
               available_crowns: nil, questions: nil, my_statistics: nil,
               opponent_statistics: nil)
  @id                   = id
  @opponent             = opponent
  @game_status          = game_status
  @language             = language
  @created              = created
  @last_turn            = last_turn
  @type                 = type
  @expiration_date      = expiration_date
  @my_turn              = my_turn
  @round_number         = round_number
  @is_random            = is_random
  @unread_messages      = unread_messages
  @status_version       = status_version
  @available_crowns     = available_crowns
  @questions            = questions
  @my_statistics        = my_statistics
  @opponent_statistics  = opponent_statistics
end

Public Instance Methods

playable?() click to toggle source

Public: Returns true if the game has not ended and it is the user's turn.

Examples

if game.playable?
  ... do something ...
end

Returns a boolean indicating if the game is playable.

# File lib/triviacrack/game.rb, line 95
def playable?
  @my_turn && @game_status != :ended
end