Class: ThatLanguage::ResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/that_language/result_set.rb

Constant Summary collapse

NO_RESULT =

TODO: Handle no result in a better way (NullObject anyone?)

Result.new(language_code: nil)

Instance Method Summary collapse

Constructor Details

#initialize(words_count) ⇒ ResultSet

Returns a new instance of ResultSet.



8
9
10
# File 'lib/that_language/result_set.rb', line 8

def initialize(words_count)
  @words_count = words_count
end

Instance Method Details

#each(&block) ⇒ Object



26
27
28
# File 'lib/that_language/result_set.rb', line 26

def each(&block)
  results.each(&block)
end

#for(key) ⇒ Object



12
13
14
# File 'lib/that_language/result_set.rb', line 12

def for(key)
  lookup[key]
end

#resultsObject



20
21
22
23
24
# File 'lib/that_language/result_set.rb', line 20

def results
  finalize_results

  _results.sort.reverse
end

#to_hObject



30
31
32
33
34
# File 'lib/that_language/result_set.rb', line 30

def to_h
  {
    results: results.map(&:to_h)
  }
end

#to_jsonObject



36
37
38
# File 'lib/that_language/result_set.rb', line 36

def to_json
  to_h.to_json
end

#winnerObject



16
17
18
# File 'lib/that_language/result_set.rb', line 16

def winner
  results.max || NO_RESULT
end