Class: TriviaCrack::Game
- Inherits:
-
Object
- Object
- TriviaCrack::Game
- Defined in:
- lib/triviacrack/game.rb
Instance Attribute Summary collapse
-
#available_crowns ⇒ Object
readonly
Public: Array of available crowns that can be won by the user.
-
#created ⇒ Object
readonly
Public: The datetime on which the game was created.
-
#expiration_date ⇒ Object
readonly
Public: The datetime on which the game will expire.
-
#game_status ⇒ Object
readonly
Public: The current status of the game (e.g. :active, :ended, :pending_approval).
-
#id ⇒ Object
readonly
Public: The unique identifier of the game.
-
#is_random ⇒ Object
readonly
Public: Boolean indicating whether the game was created with a random opponent.
-
#language ⇒ Object
readonly
Public: The language used for the game (e.g. :en).
-
#last_turn ⇒ Object
readonly
Public: The datetime on which the last turn was taken.
-
#my_statistics ⇒ Object
readonly
Public: TriviaCrack::GameStatistics for the user.
-
#my_turn ⇒ Object
readonly
Public: Boolean indicating whether it is the user’s turn.
-
#opponent ⇒ Object
readonly
Public: The TriviaCrack::User information for the opponent.
-
#opponent_statistics ⇒ Object
readonly
Public: TriviaCrack::GameStatistics for the opponent.
-
#questions ⇒ Object
readonly
Public: Array of questions that can be answered by the user.
-
#round_number ⇒ Object
readonly
Public: The number of the current round.
-
#status_version ⇒ Object
readonly
Public: The status version.
-
#type ⇒ Object
readonly
Public: The type of the game (:normal, :duel).
-
#unread_messages ⇒ Object
readonly
Public: Number of unread messages.
Instance Method Summary collapse
-
#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) ⇒ Game
constructor
A new instance of Game.
-
#playable? ⇒ Boolean
Public: Returns true if the game has not ended and it is the user’s turn.
Constructor Details
#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) ⇒ Game
Returns a new instance of Game.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 = @status_version = status_version @available_crowns = available_crowns @questions = questions @my_statistics = my_statistics @opponent_statistics = opponent_statistics end |
Instance Attribute Details
#available_crowns ⇒ Object (readonly)
Public: Array of available crowns that can be won by the user.
49 50 51 |
# File 'lib/triviacrack/game.rb', line 49 def available_crowns @available_crowns end |
#created ⇒ Object (readonly)
Public: The datetime on which the game was created.
21 22 23 |
# File 'lib/triviacrack/game.rb', line 21 def created @created end |
#expiration_date ⇒ Object (readonly)
Public: The datetime on which the game will expire.
30 31 32 |
# File 'lib/triviacrack/game.rb', line 30 def expiration_date @expiration_date end |
#game_status ⇒ Object (readonly)
Public: The current status of the game (e.g. :active, :ended, :pending_approval).
15 16 17 |
# File 'lib/triviacrack/game.rb', line 15 def game_status @game_status end |
#id ⇒ Object (readonly)
Public: The unique identifier of the game.
8 9 10 |
# File 'lib/triviacrack/game.rb', line 8 def id @id end |
#is_random ⇒ Object (readonly)
Public: Boolean indicating whether the game was created with a random opponent.
40 41 42 |
# File 'lib/triviacrack/game.rb', line 40 def is_random @is_random end |
#language ⇒ Object (readonly)
Public: The language used for the game (e.g. :en).
18 19 20 |
# File 'lib/triviacrack/game.rb', line 18 def language @language end |
#last_turn ⇒ Object (readonly)
Public: The datetime on which the last turn was taken.
24 25 26 |
# File 'lib/triviacrack/game.rb', line 24 def last_turn @last_turn end |
#my_statistics ⇒ Object (readonly)
Public: TriviaCrack::GameStatistics for the user.
56 57 58 |
# File 'lib/triviacrack/game.rb', line 56 def my_statistics @my_statistics end |
#my_turn ⇒ Object (readonly)
Public: Boolean indicating whether it is the user’s turn.
33 34 35 |
# File 'lib/triviacrack/game.rb', line 33 def my_turn @my_turn end |
#opponent ⇒ Object (readonly)
Public: The TriviaCrack::User information for the opponent.
11 12 13 |
# File 'lib/triviacrack/game.rb', line 11 def opponent @opponent end |
#opponent_statistics ⇒ Object (readonly)
Public: TriviaCrack::GameStatistics for the opponent.
59 60 61 |
# File 'lib/triviacrack/game.rb', line 59 def opponent_statistics @opponent_statistics end |
#questions ⇒ Object (readonly)
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).
53 54 55 |
# File 'lib/triviacrack/game.rb', line 53 def questions @questions end |
#round_number ⇒ Object (readonly)
Public: The number of the current round.
36 37 38 |
# File 'lib/triviacrack/game.rb', line 36 def round_number @round_number end |
#status_version ⇒ Object (readonly)
Public: The status version.
46 47 48 |
# File 'lib/triviacrack/game.rb', line 46 def status_version @status_version end |
#type ⇒ Object (readonly)
Public: The type of the game (:normal, :duel)
27 28 29 |
# File 'lib/triviacrack/game.rb', line 27 def type @type end |
#unread_messages ⇒ Object (readonly)
Public: Number of unread messages.
43 44 45 |
# File 'lib/triviacrack/game.rb', line 43 def @unread_messages end |
Instance Method Details
#playable? ⇒ Boolean
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.
95 96 97 |
# File 'lib/triviacrack/game.rb', line 95 def playable? @my_turn && @game_status != :ended end |