Sha256: a6ab7d93d43979c5c25de672603472f2a89b1d61ceda6a7970971ea21392001e

Contents?: true

Size: 591 Bytes

Versions: 4

Compression:

Stored size: 591 Bytes

Contents

module Codebreaker
  class Statistics
    include Database

    def winners(base)
      data = multi_sort(base)
      to_table(data)
    end

    private

    def to_table(data)
      rows = []
      data.map do |i|
        row = []
        row << i.name
        row << i.difficulty
        row << i.attempts_total
        row << i.attempts_used
        row << i.hints_total
        row << i.hints_used
        rows << row
      end
      rows
    end

    def multi_sort(items)
      items.sort_by { |player| [player.difficulty, player.attempts_used, player.hints_used] }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codebreaker_PI-0.6.4 lib/entities/statistics.rb
codebreaker_PI-0.6.1 lib/entities/statistics.rb
codebreaker_PI-0.6.0 lib/entities/statistics.rb
codebreaker_PI-0.0.1 lib/entities/statistics.rb