Class: TriviaCrack::User

Inherits:
Object
  • Object
show all
Defined in:
lib/triviacrack/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, username: nil, facebook_id: nil, facebook_name: nil, coins: nil, lives: nil, max_lives: nil, unlimited_lives: nil, country: nil, extra_shots: nil, level: nil, level_points: nil, level_progress: nil, goal_points: nil, level_up: nil) ⇒ User

Returns a new instance of User.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/triviacrack/user.rb', line 54

def initialize(id:, username: nil, facebook_id: nil, facebook_name: nil,
               coins: nil, lives: nil, max_lives: nil, unlimited_lives: nil,
               country: nil, extra_shots: nil, level: nil,
               level_points: nil, level_progress: nil, goal_points: nil,
               level_up: nil)
  @id               = id
  @username         = username
  @facebook_id      = facebook_id
  @facebook_name    = facebook_name
  @coins            = coins
  @lives            = lives
  @max_lives        = max_lives
  @unlimited_lives  = unlimited_lives
  @country          = country
  @extra_shots      = extra_shots
  @level            = level
  @level_points     = level_points
  @level_progress   = level_progress
  @goal_points      = goal_points
  @level_up         = level_up
end

Instance Attribute Details

#coinsObject (readonly)

Public: The amount of coins that the user has accumulated.



21
22
23
# File 'lib/triviacrack/user.rb', line 21

def coins
  @coins
end

#countryObject (readonly)

Public: The country code of the user’s country.



33
34
35
# File 'lib/triviacrack/user.rb', line 33

def country
  @country
end

#extra_shotsObject (readonly)

Public: The number of extra shots available to the user.



36
37
38
# File 'lib/triviacrack/user.rb', line 36

def extra_shots
  @extra_shots
end

#facebook_idObject (readonly)

Public: The Facebook ID of the user (nil if the user has not linked their Facebook account).



14
15
16
# File 'lib/triviacrack/user.rb', line 14

def facebook_id
  @facebook_id
end

#facebook_nameObject (readonly)

Public: The Facebook name of the user (nil if the user has not linked their Facebook account).



18
19
20
# File 'lib/triviacrack/user.rb', line 18

def facebook_name
  @facebook_name
end

#goal_pointsObject (readonly)

Public: The user’s goal points.



49
50
51
# File 'lib/triviacrack/user.rb', line 49

def goal_points
  @goal_points
end

#idObject (readonly)

Public: The unique identifier of the user.



7
8
9
# File 'lib/triviacrack/user.rb', line 7

def id
  @id
end

#levelObject (readonly)

Public: The user’s level.



39
40
41
# File 'lib/triviacrack/user.rb', line 39

def level
  @level
end

#level_pointsObject (readonly)

Public: The experience points that the user has accumulated towards their next level.



43
44
45
# File 'lib/triviacrack/user.rb', line 43

def level_points
  @level_points
end

#level_progressObject (readonly)

Public: The percentage progress towards the next level.



46
47
48
# File 'lib/triviacrack/user.rb', line 46

def level_progress
  @level_progress
end

#level_upObject (readonly)

Public: Boolean indicating whether the user has leveled up.



52
53
54
# File 'lib/triviacrack/user.rb', line 52

def level_up
  @level_up
end

#livesObject (readonly)

Public: The amount of lives available to the user.



24
25
26
# File 'lib/triviacrack/user.rb', line 24

def lives
  @lives
end

#max_livesObject (readonly)

Public: The maximum number of lives that the user can have.



27
28
29
# File 'lib/triviacrack/user.rb', line 27

def max_lives
  @max_lives
end

#unlimited_livesObject (readonly)

Public: Boolean indicating whether the user has unlimited lives.



30
31
32
# File 'lib/triviacrack/user.rb', line 30

def unlimited_lives
  @unlimited_lives
end

#usernameObject (readonly)

Public: The unique username of the user.



10
11
12
# File 'lib/triviacrack/user.rb', line 10

def username
  @username
end

Instance Method Details

#start_new_game?Boolean

Public: Returns true if the user has one or more lives, or has unlimited lives.

Examples

if user.start_new_game?
   ... start a new game ...
end

Returns true if the user can start a new game, false otherwise.

Returns:

  • (Boolean)


86
87
88
# File 'lib/triviacrack/user.rb', line 86

def start_new_game?
  @lives >= 1 || @unlimited_lives
end