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 ADDED
@@ -0,0 +1,15 @@
1
+ # Changes
2
+
3
+ ## v0.0.5
4
+
5
+ * Ridiculous (15-20x) speed improvements.
6
+ * Fixed "--bundled" option
7
+
8
+ ## v0.0.2 - 0.0.4
9
+
10
+ * Gemified
11
+ * minor changes and improvements
12
+
13
+ ## v0.0.1
14
+
15
+ * Just a hacked-out bundle of scripts.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keyboard_battle (0.0.1)
4
+ keyboard_battle (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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(filename, keyboards)
7
- @filename = filename
8
- @keyboards = 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.combined.include?(char)
27
+ if effort = keyboard::MAP[char]
30
28
 
31
29
  # measure alternation efficiency
32
- hand = keyboard.left.include?(char) ? 'l' : 'r'
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 += EFFORT[keyboard.combined.find_index(char)]
37
+ reach_effort += effort
40
38
  end
39
+
41
40
  end
42
41
  end
43
42
  end
44
43
 
45
- results[keyboard.name.to_sym] = {
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 Qwerty < self
5
- def name
6
- "qwerty"
7
- end
4
+ class << self
8
5
 
9
- def left
10
- %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)
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
- class Dvorak < self
19
- def name
20
- "dvorak"
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
- def left
24
- %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)
25
- end
26
-
27
- def right
28
- %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)
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 Colemak < self
33
- def name
34
- "colemak"
35
- end
36
-
37
- def left
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
- attr_accessor :left, :right, :name
47
-
48
- def combined
49
- left + right
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
@@ -1,3 +1,3 @@
1
1
  module KeyboardBattle
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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.name}).to eq(%w(qwerty dvorak colemak))
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
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-08 00:00:00.000000000 Z
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