Class: ThatLanguage::ResultSet
- Inherits:
-
Object
- Object
- ThatLanguage::ResultSet
- 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
- #each(&block) ⇒ Object
- #for(key) ⇒ Object
-
#initialize(words_count) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #results ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #winner ⇒ Object
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 |
#results ⇒ Object
20 21 22 23 24 |
# File 'lib/that_language/result_set.rb', line 20 def results finalize_results _results.sort.reverse end |
#to_h ⇒ Object
30 31 32 33 34 |
# File 'lib/that_language/result_set.rb', line 30 def to_h { results: results.map(&:to_h) } end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/that_language/result_set.rb', line 36 def to_json to_h.to_json end |
#winner ⇒ Object
16 17 18 |
# File 'lib/that_language/result_set.rb', line 16 def winner results.max || NO_RESULT end |