Class: Teletype::Stats::Pair
- Inherits:
-
Object
- Object
- Teletype::Stats::Pair
- Defined in:
- lib/teletype/stats.rb
Overview
It implements hit/miss rate for second keystroke. Key miss tends occur when preceded by a certain key.
Constant Summary collapse
- THRESHOLD =
0.7
Instance Attribute Summary collapse
-
#available ⇒ Object
hit/miss is for the second key.
-
#hit ⇒ Object
hit/miss is for the second key.
-
#keys ⇒ Object
hit/miss is for the second key.
-
#miss ⇒ Object
hit/miss is for the second key.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #hit! ⇒ Object
- #inefficient? ⇒ Boolean
-
#initialize(keys, hit: 0, miss: 0, available: true) ⇒ Pair
constructor
A new instance of Pair.
- #miss! ⇒ Object
- #rate ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(keys, hit: 0, miss: 0, available: true) ⇒ Pair
Returns a new instance of Pair.
63 64 65 66 67 68 |
# File 'lib/teletype/stats.rb', line 63 def initialize(keys, hit: 0, miss: 0, available: true) @keys = keys @hit = hit @miss = miss @available = available end |
Instance Attribute Details
#available ⇒ Object
hit/miss is for the second key
61 62 63 |
# File 'lib/teletype/stats.rb', line 61 def available @available end |
#hit ⇒ Object
hit/miss is for the second key
61 62 63 |
# File 'lib/teletype/stats.rb', line 61 def hit @hit end |
#keys ⇒ Object
hit/miss is for the second key
61 62 63 |
# File 'lib/teletype/stats.rb', line 61 def keys @keys end |
#miss ⇒ Object
hit/miss is for the second key
61 62 63 |
# File 'lib/teletype/stats.rb', line 61 def miss @miss end |
Instance Method Details
#<=>(other) ⇒ Object
92 93 94 |
# File 'lib/teletype/stats.rb', line 92 def <=>(other) [rate, keys] <=> [other.rate, other.keys] end |
#hit! ⇒ Object
74 75 76 |
# File 'lib/teletype/stats.rb', line 74 def hit! @hit += 1 end |
#inefficient? ⇒ Boolean
70 71 72 |
# File 'lib/teletype/stats.rb', line 70 def inefficient? rate < THRESHOLD end |
#miss! ⇒ Object
78 79 80 |
# File 'lib/teletype/stats.rb', line 78 def miss! @miss += 1 end |
#rate ⇒ Object
82 83 84 85 86 |
# File 'lib/teletype/stats.rb', line 82 def rate return 0 if total.zero? hit / total.to_f end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/teletype/stats.rb', line 96 def to_s keys.gsub(/[\n\r]/, '↵').gsub(' ', '␣') end |
#total ⇒ Object
88 89 90 |
# File 'lib/teletype/stats.rb', line 88 def total hit + miss end |