class Codebreaker::Sorter
Constants
- CONDITIONAL_ARRAY
Attributes
data[R]
Public Class Methods
new(data)
click to toggle source
# File lib/codebreaker/sorter.rb, line 9 def initialize(data) @data = data end
Public Instance Methods
call()
click to toggle source
# File lib/codebreaker/sorter.rb, line 13 def call sorted = sort_by_hints(data) sorted = sort_by_attempts(sorted) sorted = sort_by_difficulties(sorted) sorted end
Private Instance Methods
sort_by_attempts(data)
click to toggle source
# File lib/codebreaker/sorter.rb, line 26 def sort_by_attempts(data) data.sort_by { |row| row[:attempts_used] } end
sort_by_difficulties(data)
click to toggle source
# File lib/codebreaker/sorter.rb, line 30 def sort_by_difficulties(data) data.sort_by { |row| CONDITIONAL_ARRAY.index(row[:difficulty]) } end
sort_by_hints(data)
click to toggle source
# File lib/codebreaker/sorter.rb, line 22 def sort_by_hints(data) data.sort_by { |row| row[:hints_used] } end