Twiddler Utils C0 Coverage Information - RCov

lib/twiddler/target_builder.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/twiddler/target_builder.rb 120 102
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 require 'fileutils'
2 
3 module Twiddler
4   module TargetBuilder
5     def self.build(output_dir, dictionary, config)
6       FileUtils::mkdir_p(output_dir)
7       File::open(dictionary, "r") do |dict|
8         Builder::registered.each do |klass|
9           dict.rewind
10           klass.new(output_dir, dict, config).go
11         end
12       end
13     end
14 
15     class Builder
16       class << self
17         def register
18           @@registered ||= []
19           @@registered << self
20         end
21 
22         def registered
23           @@registered || []
24         end
25       end
26 
27       def initialize(dir, dict, config)
28         @dir = dir
29         @dict = dict
30         @config = config
31       end
32 
33       def output_to(name)
34         File::open(File::expand_path("#{name}.list", @dir), "w") do |file|
35           yield(file)
36         end
37       end
38 
39       def go
40       end
41     end
42 
43     class RegexpBuilder < Builder
44       def match_any_of(list)
45         return "(?:#{list.map{|it| Regexp::escape(it)}.join(")|(?:")})"
46       end
47       def go
48         output_to(filename) do |file|
49           @dict.grep(regexp) do |word|
50             file.puts(word)
51           end
52         end
53       end
54     end
55 
56     class ShortWords < RegexpBuilder
57       register
58 
59       def filename
60         "Short Words"
61       end
62 
63       def regexp
64         /^.{1,5}$/
65       end
66     end
67 
68     class Macros < RegexpBuilder
69       register
70 
71       def filename
72         "Macros"
73       end
74 
75       def regexp
76         macros = @config.keyboard.find_all do |chord|
77           chord.keystrokes.length > 1 and chord.keystrokes.all? do |stroke|
78             stroke[1].empty?
79           end
80         end
81         return %r{^.{0,1}(?:#{match_any_of(macros.map{|chord| chord.render_action})}).{0,1}$}
82       end
83     end
84 
85     class Flow < RegexpBuilder
86       register
87 
88       def filename
89         "Flow"
90       end
91 
92       def regexp
93         flow = []
94         chords = @config.keyboard.find_all do |chord|
95           chord.single? and chord.keystrokes[0][1].empty? and Config.keytable.is_tagged?(chord.keystrokes[0][0], :letters)
96         end
97 
98         chords.each do |first|
99           chords.each do |second|
100             next if first == second
101             pairs = first.rows.zip(second.rows).find_all{|one,two| one != two}
102             case pairs.length 
103             when 1
104               flow << first.render_action + second.render_action
105               next
106             when 2
107               next if pairs.find{|pair| !pair.include?(:open)}
108               if pairs[0][0] == pairs[1][1] and pairs[0][1] == pairs[1][0]
109                 flow << first.render_action + second.render_action
110                 next
111               end
112             end
113           end
114         end
115 
116         return %r{^.{0,1}(?:#{match_any_of(flow)}).{0,1}$}
117       end
118     end
119   end
120 end

Generated on Tue May 03 12:22:31 -0700 2011 with rcov 0.9.7.1