Sha256: b9fb1d218748b456836c2a3476248d67f358a3d45444157a1ec8e0d77f3facf7

Contents?: true

Size: 627 Bytes

Versions: 8

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true

module Codebreaker
  module Entities
    class Statistics
      def stats(list)
        difficulties = list.group_by { |score| score[:difficulty] }
        Game::DIFFICULTIES.keys.reverse.reduce([]) do |sorted_difficulties, difficulty_name|
          if difficulties[difficulty_name]
            sorted_difficulties + stats_sort(difficulties[difficulty_name])
          else
            sorted_difficulties
          end
        end
      end

      private

      def stats_sort(scores)
        scores.sort_by! { |score| [score[:attempts_used], score[:hints_used]] }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codebreaker_marian-0.3.6 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.5 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.4 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.3 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.2 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.1 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.3.0 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.9 lib/codebreaker_marian/entities/statistics.rb