Class: ThatLanguage::Result
- Inherits:
-
Object
- Object
- ThatLanguage::Result
- Defined in:
- lib/that_language/result.rb
Instance Attribute Summary collapse
-
#hit_count ⇒ Object
readonly
Returns the value of attribute hit_count.
-
#language_code ⇒ Object
readonly
Returns the value of attribute language_code.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#words_count ⇒ Object
Returns the value of attribute words_count.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=>(other) ⇒ Object
- #>(other) ⇒ Object
- #add(value) ⇒ Object
- #confidence ⇒ Object
- #hit_ratio ⇒ Object
-
#initialize(language_code:) ⇒ Result
constructor
A new instance of Result.
- #language ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(language_code:) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 |
# File 'lib/that_language/result.rb', line 8 def initialize(language_code:) @language_code = language_code @value = 0.0 @hit_count = 0 @words_count = 0 end |
Instance Attribute Details
#hit_count ⇒ Object (readonly)
Returns the value of attribute hit_count.
5 6 7 |
# File 'lib/that_language/result.rb', line 5 def hit_count @hit_count end |
#language_code ⇒ Object (readonly)
Returns the value of attribute language_code.
5 6 7 |
# File 'lib/that_language/result.rb', line 5 def language_code @language_code end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/that_language/result.rb', line 5 def value @value end |
#words_count ⇒ Object
Returns the value of attribute words_count.
6 7 8 |
# File 'lib/that_language/result.rb', line 6 def words_count @words_count end |
Instance Method Details
#<(other) ⇒ Object
38 39 40 |
# File 'lib/that_language/result.rb', line 38 def <(other) value < other.value end |
#<=>(other) ⇒ Object
34 35 36 |
# File 'lib/that_language/result.rb', line 34 def <=>(other) value <=> other.value end |
#>(other) ⇒ Object
42 43 44 |
# File 'lib/that_language/result.rb', line 42 def >(other) value > other.value end |
#add(value) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/that_language/result.rb', line 15 def add(value) return @value unless value > 0 @hit_count += 1 @value += value end |
#confidence ⇒ Object
22 23 24 25 26 |
# File 'lib/that_language/result.rb', line 22 def confidence return 0 unless words_count > 0 value / words_count end |
#hit_ratio ⇒ Object
28 29 30 31 32 |
# File 'lib/that_language/result.rb', line 28 def hit_ratio return 0.0 if @words_count == 0 @hit_count.to_f / @words_count end |
#language ⇒ Object
46 47 48 |
# File 'lib/that_language/result.rb', line 46 def language Iso639[language_code] if language_code end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/that_language/result.rb', line 50 def to_h { language: language, language_code: language_code, confidence: confidence, value: value, hit_ratio: hit_ratio, hit_count: hit_count, words_count: words_count } end |
#to_json ⇒ Object
62 63 64 |
# File 'lib/that_language/result.rb', line 62 def to_json to_h.to_json end |