keyboard_battle 0.0.4 → 0.0.5
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.
- data/CHANGES +15 -0
- data/Gemfile.lock +1 -1
- data/lib/keyboard_battle/command_dispatcher.rb +2 -1
- data/lib/keyboard_battle/exercise.rb +9 -15
- data/lib/keyboard_battle/keyboard.rb +28 -43
- data/lib/keyboard_battle/version.rb +1 -1
- data/spec/keyboard_battle/exercise_spec.rb +1 -1
- metadata +4 -2
data/CHANGES
ADDED
data/Gemfile.lock
CHANGED
@@ -2,10 +2,11 @@ module KeyboardBattle
|
|
2
2
|
class CommandDispatcher
|
3
3
|
|
4
4
|
def initialize(args)
|
5
|
+
|
5
6
|
if opt = args.first
|
6
7
|
case opt
|
7
8
|
when '--bundled'
|
8
|
-
self.run(Dir.glob('texts/*.txt
|
9
|
+
self.run(Dir.glob("#{File.expand_path('../../..', __FILE__)}/texts/*.txt"))
|
9
10
|
else
|
10
11
|
self.run(args)
|
11
12
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
module KeyboardBattle
|
2
2
|
class Exercise
|
3
3
|
|
4
|
-
attr_accessor :results, :filename
|
4
|
+
attr_accessor :results, :filename, :keyboards
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@filename =
|
8
|
-
@keyboards =
|
6
|
+
def initialize(f, k)
|
7
|
+
@filename = f
|
8
|
+
@keyboards = k
|
9
9
|
@results = run
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
attr_accessor :keyboards
|
15
|
-
|
16
14
|
# tests a passage of text for reach effort expended (zero for home row,
|
17
15
|
# increasing for reach), and hand alternation effort. In both values,
|
18
16
|
# lower is better.
|
@@ -26,23 +24,24 @@ module KeyboardBattle
|
|
26
24
|
open_and_process(filename,'r') do |file|
|
27
25
|
while line = file.gets
|
28
26
|
line.each_char do |char|
|
29
|
-
if keyboard
|
27
|
+
if effort = keyboard::MAP[char]
|
30
28
|
|
31
29
|
# measure alternation efficiency
|
32
|
-
hand = keyboard.
|
30
|
+
hand = keyboard::LEFT_KEYS.include?(char) ? 'l' : 'r'
|
33
31
|
if prev_hand
|
34
32
|
alternation_effort += (hand == prev_hand) ? 1 : 0
|
35
33
|
end
|
36
34
|
prev_hand = hand
|
37
35
|
|
38
36
|
# measure reach efficiency
|
39
|
-
reach_effort +=
|
37
|
+
reach_effort += effort
|
40
38
|
end
|
39
|
+
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
results[keyboard.
|
44
|
+
results[keyboard::NAME.to_sym] = {
|
46
45
|
:alternation_effort => alternation_effort,
|
47
46
|
:reach_effort => reach_effort,
|
48
47
|
:raw_score => (alternation_effort + reach_effort)
|
@@ -57,10 +56,5 @@ module KeyboardBattle
|
|
57
56
|
f.close()
|
58
57
|
end
|
59
58
|
|
60
|
-
EFFORT = ( # left hand + right hand effort values
|
61
|
-
%w(3 2 2 2 2 2 2 1 1 1 1 1 0 0 0 0 1 1 1 1 1 2 3 2 2 2 2 2 2 1 1 1 1 1 0 0 0 0 1 1 1 1 1 2) +
|
62
|
-
%w(2 2 2 2 2 2 1 1 1 1 1 1 2 3 1 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 2 3 1 0 0 0 0 1 1 1 1 1 1)
|
63
|
-
).collect { |el| el.to_i }
|
64
|
-
|
65
59
|
end
|
66
60
|
end
|
@@ -1,60 +1,45 @@
|
|
1
1
|
module KeyboardBattle
|
2
2
|
class Keyboard
|
3
3
|
|
4
|
-
class
|
5
|
-
def name
|
6
|
-
"qwerty"
|
7
|
-
end
|
4
|
+
class << self
|
8
5
|
|
9
|
-
def
|
10
|
-
|
6
|
+
def all
|
7
|
+
[
|
8
|
+
KeyboardBattle::Keyboard::Qwerty,
|
9
|
+
KeyboardBattle::Keyboard::Dvorak,
|
10
|
+
KeyboardBattle::Keyboard::Colemak
|
11
|
+
]
|
11
12
|
end
|
12
13
|
|
13
|
-
def right
|
14
|
-
%w(7 8 9 0 - = y u i o p [ ] \\ h j k l ; ' n m , . / & * ( ) _ + Y U I O P { } | H J K L : " N M < > ?)
|
15
|
-
end
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
LEFT_EFFORT = %w(3 2 2 2 2 2 2 1 1 1 1 1 0 0 0 0 1 1 1 1 1 2 3 2 2 2 2 2 2 1 1 1 1 1 0 0 0 0 1 1 1 1 1 2).collect { |el| el.to_i }
|
17
|
+
RIGHT_EFFORT = %w(2 2 2 2 2 2 1 1 1 1 1 1 2 3 1 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 2 3 1 0 0 0 0 1 1 1 1 1 1).collect { |el| el.to_i }
|
18
|
+
COMBINED_EFFORT = LEFT_EFFORT + RIGHT_EFFORT
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
20
|
+
class Qwerty < Keyboard
|
21
|
+
NAME = "qwerty"
|
22
|
+
LEFT_KEYS = %w(` 1 2 3 4 5 6 q w e r t a s d f g z x c v b ~ ! @ # $ % ^ Q W E R T A S D F G Z X C V B)
|
23
|
+
RIGHT_KEYS = %w(7 8 9 0 - = y u i o p [ ] \\ h j k l ; ' n m , . / & * ( ) _ + Y U I O P { } | H J K L : " N M < > ?)
|
24
|
+
COMBINED_KEYS = LEFT_KEYS + RIGHT_KEYS
|
25
|
+
MAP = Hash[COMBINED_KEYS.zip(Keyboard::COMBINED_EFFORT)]
|
30
26
|
end
|
31
27
|
|
32
|
-
class
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
%w(` 1 2 3 4 5 6 q w f p g a r s t d z x c v b ~ ! @ # $ % ^ Q W F P G A R S T D Z X C V B)
|
39
|
-
end
|
40
|
-
|
41
|
-
def right
|
42
|
-
%w(7 8 9 0 - = j l u y : [ ] \\ h n e i o ' k m , . / & * ( ) _ + J L U Y ; { } | H N E I O " K M < > ?)
|
43
|
-
end
|
28
|
+
class Dvorak < Keyboard
|
29
|
+
NAME = "dvorak"
|
30
|
+
LEFT_KEYS = %w(` 1 2 3 4 5 6 ' , . p y a o e u i ; q j k x ~ ! @ # $ % ^ " < > P Y A O E U I : Q J K X)
|
31
|
+
RIGHT_KEYS = %w(7 8 9 0 [ ] f g c r l / = \\ d h t n s - b m w v z & * ( ) { } F G C R L ? + | D H T N S _ B M W V Z)
|
32
|
+
COMBINED_KEYS = LEFT_KEYS + RIGHT_KEYS
|
33
|
+
MAP = Hash[COMBINED_KEYS.zip(Keyboard::COMBINED_EFFORT)]
|
44
34
|
end
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
class Colemak < Keyboard
|
37
|
+
NAME = "colemak"
|
38
|
+
LEFT_KEYS = %w(` 1 2 3 4 5 6 q w f p g a r s t d z x c v b ~ ! @ # $ % ^ Q W F P G A R S T D Z X C V B)
|
39
|
+
RIGHT_KEYS = %w(7 8 9 0 - = j l u y : [ ] \\ h n e i o ' k m , . / & * ( ) _ + J L U Y ; { } | H N E I O " K M < > ?)
|
40
|
+
COMBINED_KEYS = LEFT_KEYS + RIGHT_KEYS
|
41
|
+
MAP = Hash[COMBINED_KEYS.zip(Keyboard::COMBINED_EFFORT)]
|
50
42
|
end
|
51
43
|
|
52
|
-
def self.all
|
53
|
-
[
|
54
|
-
KeyboardBattle::Keyboard::Qwerty.new,
|
55
|
-
KeyboardBattle::Keyboard::Dvorak.new,
|
56
|
-
KeyboardBattle::Keyboard::Colemak.new
|
57
|
-
]
|
58
|
-
end
|
59
44
|
end
|
60
45
|
end
|
@@ -6,7 +6,7 @@ describe KeyboardBattle::Exercise do
|
|
6
6
|
let(:exercise) { KeyboardBattle::Exercise.new('texts/qbf.txt', KeyboardBattle::Keyboard.all) }
|
7
7
|
|
8
8
|
it "loads the keyboards" do
|
9
|
-
expect(exercise.send(:keyboards).map {|k| k
|
9
|
+
expect(exercise.send(:keyboards).map {|k| k::NAME}).to eq(%w(qwerty dvorak colemak))
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "when processing texts" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keyboard_battle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -36,12 +36,14 @@ executables:
|
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
+
- CHANGES
|
39
40
|
- Gemfile
|
40
41
|
- Gemfile.lock
|
41
42
|
- LICENSE
|
42
43
|
- README.md
|
43
44
|
- Rakefile
|
44
45
|
- bin/keyboard_battle
|
46
|
+
- keyboard_battle-0.0.5.gem
|
45
47
|
- keyboard_battle.gemspec
|
46
48
|
- lib/keyboard_battle.rb
|
47
49
|
- lib/keyboard_battle/command_dispatcher.rb
|