Class: Codebreaker::Statistic
- Inherits:
-
Object
- Object
- Codebreaker::Statistic
- Includes:
- YamlFile
- Defined in:
- lib/codebreaker/statistic.rb
Constant Summary collapse
- STAT_HEADER_LIST =
%w[rating name difficulty attempts_total attempts_used hints_total hints_used].freeze
- STAT_FILE_PATH =
'statistic.yml'.freeze
Instance Attribute Summary collapse
-
#headings ⇒ Object
readonly
Returns the value of attribute headings.
-
#statistic ⇒ Object
readonly
Returns the value of attribute statistic.
Instance Method Summary collapse
-
#initialize ⇒ Statistic
constructor
A new instance of Statistic.
- #statistic_add_item(name:, difficulty:, game_stage:) ⇒ Object
- #statistic_get ⇒ Object
- #statistic_save ⇒ Object
Methods included from YamlFile
Constructor Details
#initialize ⇒ Statistic
Returns a new instance of Statistic.
9 10 11 12 |
# File 'lib/codebreaker/statistic.rb', line 9 def initialize @headings = STAT_HEADER_LIST @statistic_items = [] end |
Instance Attribute Details
#headings ⇒ Object (readonly)
Returns the value of attribute headings.
8 9 10 |
# File 'lib/codebreaker/statistic.rb', line 8 def headings @headings end |
#statistic ⇒ Object (readonly)
Returns the value of attribute statistic.
8 9 10 |
# File 'lib/codebreaker/statistic.rb', line 8 def statistic @statistic end |
Instance Method Details
#statistic_add_item(name:, difficulty:, game_stage:) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/codebreaker/statistic.rb', line 23 def statistic_add_item(name:, difficulty:, game_stage:) @statistic_items << { name: name, difficulty: difficulty.name, attempts_total: game_stage.attempts, attempts_used: game_stage.step_number, hints_total: difficulty.hints, hints_used: game_stage.hint_used } end |
#statistic_get ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/codebreaker/statistic.rb', line 14 def statistic_get statistic_load statistic_sort @statistic_items.each_with_index.map do |stat, index| [index.next, stat[:name], stat[:difficulty], stat[:attempts_total], stat[:attempts_used], stat[:hints_total], stat[:hints_used]] end end |
#statistic_save ⇒ Object
32 33 34 |
# File 'lib/codebreaker/statistic.rb', line 32 def statistic_save YamlFile.save(STAT_FILE_PATH, @statistic_items) end |