Class: Statistic

Inherits:
Object
  • Object
show all
Defined in:
lib/services/statistic_service.rb

Class Method Summary collapse

Class Method Details

.difficulty_nameObject



41
42
43
# File 'lib/services/statistic_service.rb', line 41

def difficulty_name
  game.difficulty_name
end

.gameObject



49
50
51
# File 'lib/services/statistic_service.rb', line 49

def game
  CurrentGame.game
end

.generate_statsObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/services/statistic_service.rb', line 5

def generate_stats
  {
    name: player_name,
    difficulty: difficulty_name,
    total_attempts: total_attempts,
    used_attempts: used_attempts,
    total_hints: total_hints,
    used_hints: used_hints,
    date: Time.now
  }
end

.player_nameObject



45
46
47
# File 'lib/services/statistic_service.rb', line 45

def player_name
  game.player_name
end

.sort_statsObject



17
18
19
# File 'lib/services/statistic_service.rb', line 17

def sort_stats
  stats.sort_by { |player| [player[:total_attempts], player[:used_attempts], player[:used_hints]] }
end

.statsObject



21
22
23
# File 'lib/services/statistic_service.rb', line 21

def stats
  DbUtils.get(DB) || []
end

.total_attemptsObject



25
26
27
# File 'lib/services/statistic_service.rb', line 25

def total_attempts
  DIFFICULTIES[game.difficulty_name.to_sym][:attempts]
end

.total_hintsObject



33
34
35
# File 'lib/services/statistic_service.rb', line 33

def total_hints
  DIFFICULTIES[game.difficulty_name.to_sym][:hints]
end

.used_attemptsObject



29
30
31
# File 'lib/services/statistic_service.rb', line 29

def used_attempts
  DIFFICULTIES[game.difficulty_name.to_sym][:attempts] - game.attempts
end

.used_hintsObject



37
38
39
# File 'lib/services/statistic_service.rb', line 37

def used_hints
  DIFFICULTIES[game.difficulty_name.to_sym][:hints] - game.hints
end