lib/codebreaker/statistic.rb in codebreaker_bo-0.1.6 vs lib/codebreaker/statistic.rb in codebreaker_bo-0.1.7

- old
+ new

@@ -1,26 +1,30 @@ # frozen_string_literal: true module Codebreaker class Statistic def collect_statistic(hash) + game_date = Time.new.strftime '%Y/%m/%d' @stat = [{ user_name: hash[:user_name], difficulty: hash[:difficulty], attempts_total: hash[:attempts_total], attempts_used: hash[:attempts_used], hints_total: hash[:hints_total], - hints_used: hash[:hints_used] + hints_used: hash[:hints_used], + date: game_date }] save_statistic end def show_statistic @items = YAML.load_file(Constants::PATH) - @items.sort_by! { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] } + return if @items.nil? + + @items.sort_by! { |game| [game[:difficulty].reverse, game[:attempts_used], game[:hints_used]] } @items.each_with_index.map do |stat, index| [index.next, stat[:user_name], stat[:difficulty], stat[:attempts_total], - stat[:attempts_used], stat[:hints_total], stat[:hints_used]] + stat[:attempts_used], stat[:hints_total], stat[:hints_used], stat[:date]] end end def save_statistic yaml_data = YAML.load_file(Constants::PATH)