Twiddler Utils C0 Coverage Information - RCov

lib/twiddler/parser.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/twiddler/parser.rb 97 81
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 'twiddler/config'
2 
3 module Twiddler
4   class Parser
5     def self.parse(data)
6       version = *data.unpack("c")
7       case version
8       when 4
9         V4Parser.new(data, 1).go.parsed
10       end
11     end
12 
13     class V4Parser
14       def initialize(raw, skipped = 0)
15         @data = raw
16         @refs = Hash.new{|h,k| h[k] = [:missing_ref]}
17         bytes_hex
18         @index = 0
19         consume("x" * skipped)
20         bytes_hex
21         @config = Config.new()
22       end
23 
24       def parsed
25         return @config
26       end
27 
28       def consume(template)
29         old_len = @data.length
30         values = @data.unpack(template + "a*")
31         @data = values.pop
32         @index += old_len - @data.length
33         return values
34       end
35 
36       def bytes_hex(count = 8)
37         "0x%04x:#{' %02x'*count}" % ([@index] + @data.unpack("c" * count))
38       end
39 
40       def go()
41         total_size = @data.length + 1
42         @keyboard_chord_table, @mouse_chord_table, @multichar_table = *consume("vvv")
43 
44         @config.configs[:raw] = *consume("a#{@keyboard_chord_table - @index}")
45 
46         until @index >= @mouse_chord_table
47           key1234, mod_or_ff, keyindex = consume("B16B8c")
48           exit if @index > 685 
49           if keyindex == 0 and 
50             key1234 == "0000000000000000" and 
51             mod_or_ff == "00000000"
52             next
53           end
54 
55           chord = Config::KeyChord.new
56           chord.keydata = key1234
57 
58           if(mod_or_ff == "11111111")
59             @refs[keyindex] = chord
60           else
61             chord.add_keystroke(mod_or_ff, keyindex)
62           end
63 
64           @config.keyboard << chord
65         end
66 
67         while @index < @multichar_table
68           key1234, data = consume("B16B8")
69           if key1234 == "0000000000000000" and 
70             data == "00000000"
71             next
72           end
73 
74           chord_record = Config::MouseChord.new
75           chord_record.keydata = key1234
76           chord_record.data = data
77           @config.mouse << chord_record
78         end
79 
80         data_idx = 0
81         until @data.size == 0 do
82           data_size = *consume("v")
83 
84           chord_data = []
85           ((data_size-1)/2).times do 
86             mod, idx = *consume("B8c")
87             next if idx == 0 #Not sure this is sufficient
88             @refs[data_idx].add_keystroke(mod, idx)
89           end
90           data_idx += 1
91         end
92 
93         return self
94       end
95     end
96   end
97 end

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