teletype 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3d17c040e59cad3900c7fd183a9458d640fc00e22d9e513f0cf2a6ad7420747
4
- data.tar.gz: aae9d399a93ba481d3baee7090faade55d3285e4f6307cd62329760332b71d22
3
+ metadata.gz: 667cfea43d9fa584b9dab342618c78d850953eddcf78268527d78e471f322b9f
4
+ data.tar.gz: 83581a95089f771bb038022c6c91d03f734d5c5712b5d8dfa2fb568047272ec9
5
5
  SHA512:
6
- metadata.gz: 55907ec80e180e4393de75b6a4d3f09bebf8f9d70517b13f3ff88d62fa62e177d9b97d551087b820b46930ffece9f1a96a476122f53db34decf0fb4221995d64
7
- data.tar.gz: 94ffe5bbbdf66706350ca3d999e751a0e49681c7e4ededcf50852ffeff30bd6c4376cbf437a6fcca3760ac9dcc5a5905735e6bbe44513126016c3e1631efda47
6
+ metadata.gz: 14f1e845ee7667b54bf32b11238a3542477161d35d8717d20349c189b1c92cbcb95c6fd071bfcd6d9d05a109f07410f1343e21ba20089b0c03ea54251f8cbe67
7
+ data.tar.gz: a863e8fc6da18cca16ad62941f4cbe78e66e5534979a46d59709a133edbe07688fbfd22d88f18db5727f32e815289580be59154abf30860776fb16c4f044c333
data/README.md CHANGED
@@ -12,7 +12,10 @@
12
12
  ### Usage
13
13
 
14
14
  Practice numeric keys:
15
- `teletype number`
15
+ `teletype base/number.txt`
16
+
17
+ Practice basic keys(numeric and letters):
18
+ `teletype base`
16
19
 
17
20
  Practice with ruby code:
18
21
  `teletype ruby`
data/bin/teletype CHANGED
@@ -12,12 +12,13 @@ if ARGV.first == '--list'
12
12
  exit
13
13
  end
14
14
 
15
- text = ''
16
- paths = []
17
- paths << 'base' if ARGV.length.zero?
15
+ paths = ARGV
16
+ paths << 'base' if paths.length.zero?
18
17
 
18
+ text = ''
19
19
  paths.each do |path|
20
20
  path = File.join(exercises, path)
21
+
21
22
  if File.directory?(path)
22
23
  Dir.glob(File.join(path, '*.*')).each do |file|
23
24
  text += File.read(file)
@@ -4,7 +4,7 @@ module Teletype
4
4
  # Pager divides lines of text into proper screen size and provides page suggestion
5
5
  # based on statistics of click accuracy.
6
6
  class Pager
7
- SUGGEST = 1
7
+ SUGGEST = 3
8
8
 
9
9
  def initialize(lines, stats, height)
10
10
  @lines = lines
@@ -17,7 +17,7 @@ module Teletype
17
17
  yield lines
18
18
 
19
19
  loop do
20
- suggestions = @stats.suggestions
20
+ suggestions = @stats.suggestions(@lines)
21
21
  break if suggestions.empty?
22
22
 
23
23
  yield pick(suggestions)
@@ -5,7 +5,7 @@ module Teletype
5
5
  class Practice
6
6
  def initialize(text, height: 5, width: 120)
7
7
  @screen = Screen.new(height: height, width: width)
8
- @stats = Stats.new
8
+ @stats = Stats.new(text)
9
9
 
10
10
  @lines = []
11
11
  text.each_line do |line|
@@ -3,23 +3,26 @@
3
3
  module Teletype
4
4
  # Stats keep track of hit/miss rate for each key and suggests a key that needs more practice.
5
5
  class Stats
6
- def initialize
6
+ def initialize(text)
7
7
  @previous = nil
8
8
  @pairs = {}
9
- load
9
+ load(text)
10
10
  end
11
11
 
12
- def load
12
+ def load(text)
13
13
  return unless File.exist?(file)
14
14
 
15
15
  File.readlines(file).each do |line|
16
16
  keys, hit, miss = line.split("\t")
17
- @pairs[keys] = Pair.new(keys, hit: Integer(hit), miss: Integer(miss))
17
+ @pairs[keys] = Pair.new(keys,
18
+ hit: Integer(hit),
19
+ miss: Integer(miss),
20
+ available: text.scan(keys).count.positive?)
18
21
  end
19
22
  end
20
23
 
21
24
  def save
22
- File.write(file, @pairs.map {|k, p| [k, p.hit, p.miss].join("\t")}.join("\n"))
25
+ File.write(file, @pairs.map { |k, p| [k, p.hit, p.miss].join("\t") }.join("\n"))
23
26
  end
24
27
 
25
28
  def file
@@ -43,26 +46,27 @@ module Teletype
43
46
  @pairs[keys] ||= Pair.new(keys)
44
47
  end
45
48
 
46
- def suggestions
47
- @pairs.values.select(&:inefficient?).sort.map(&:keys)
49
+ def suggestions(_lines)
50
+ @pairs.values.select(&:available).select(&:inefficient?).sort.map(&:keys)
48
51
  end
49
52
 
50
53
  def rankings
51
- @pairs.values.sort.first(10).map(&:to_s).join(' ')
54
+ @pairs.values.select(&:available).sort.first(10).map(&:to_s).join(' ')
52
55
  end
53
56
 
54
57
  # It implements hit/miss rate for second keystroke.
55
- # Sometimes a key tends be a miss only when preceded by a certain key.
58
+ # Key miss tends occur when preceded by a certain key.
56
59
  class Pair
57
- THRESHOLD = 0.8
60
+ THRESHOLD = 0.7
58
61
 
59
62
  # hit/miss is for the second key
60
- attr_accessor :keys, :hit, :miss
63
+ attr_accessor :keys, :hit, :miss, :available
61
64
 
62
- def initialize(keys, hit: 0, miss: 0)
65
+ def initialize(keys, hit: 0, miss: 0, available: true)
63
66
  @keys = keys
64
67
  @hit = hit
65
68
  @miss = miss
69
+ @available = available
66
70
  end
67
71
 
68
72
  def inefficient?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teletype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ochirkhuyag.L
@@ -39,7 +39,6 @@ executables:
39
39
  extensions: []
40
40
  extra_rdoc_files: []
41
41
  files:
42
- - LICENSE.txt
43
42
  - README.md
44
43
  - Rakefile
45
44
  - bin/teletype
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2021 Ochirkhuyag Lkhagva
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.