C0 code coverage information

Generated on Tue Oct 16 11:40:49 -0400 2007 with rcov 0.8.0


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.
Name Total lines Lines of code Total coverage Code coverage
lib/alexandria/scanners/cuecat.rb 104 62
97.1% 
96.8% 
  1 # Copyright (C) 2005-2006 Christopher Cyll
  2 #
  3 # Alexandria is free software; you can redistribute it and/or
  4 # modify it under the terms of the GNU General Public License as
  5 # published by the Free Software Foundation; either version 2 of the
  6 # License, or (at your option) any later version.
  7 #
  8 # Alexandria is distributed in the hope that it will be useful,
  9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11 # General Public License for more details.
 12 #
 13 # You should have received a copy of the GNU General Public
 14 # License along with Alexandria; see the file COPYING.  If not,
 15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 16 # Boston, MA 02111-1307, USA.
 17 
 18 require 'alexandria/scanners'
 19 
 20 module Alexandria
 21   module Scanners
 22 
 23     class CueCat
 24 
 25       def name()
 26         return "CueCat"
 27       end
 28 
 29       # Checks if data looks like cuecat input
 30       def match?(data)
 31         data.chomp!
 32         return false if data[-1] != ?.
 33         fields = data.split('.')
 34         return false if fields.size != 4
 35         return false if fields[2].size != 4
 36         return true
 37       end
 38 
 39       # Decodes CueCat input into ISBN
 40       # The following code is adapted from Skip Rosebaugh's public
 41       # domain perl implementation.
 42       def decode(data)
 43         data.chomp!
 44         fields = data.split('.')
 45         fields.shift # First part is gibberish
 46         fields.shift # Second part is cuecat serial number
 47         type, code = fields.map {|field| decode_field(field) }
 48 
 49         if type == 'IB5'
 50           type = 'IBN'
 51           code = code[0, 13]
 52         end
 53         
 54         return code if type == 'IBN'
 55                       
 56         raise "Don't know how to handle type #{type} (barcode: #{code})"
 57       end
 58 
 59       private
 60         
 61       def decode_field (encoded)
 62         seq = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-';
 63       
 64         chars   = encoded.split(//)
 65         values  = chars.map {|c| seq.index(c) }
 66         
 67         padding = pad(values)
 68         result  = calc(values)
 69         result  = result[0, result.length - padding]
 70         return result
 71       end
 72     
 73       def calc (values)
 74         result = ''
 75         while values.length > 0
 76           num = ((values[0] << 6 | values[1]) << 6 | values[2]) << 6 | values[3]
 77           result += ((num >> 16) ^ 67).chr
 78           result += ((num >> 8 & 255) ^ 67).chr
 79           result += ((num & 255) ^ 67).chr
 80           
 81           values = values[4, values.length]
 82         end
 83         return result
 84       end
 85       
 86       def pad (array)
 87         length = array.length % 4
 88       
 89         if length != 0
 90           raise "Error parsing CueCat input" if length == 1
 91                                                
 92           length = 4 - length
 93           length.times { array.push(0) }
 94         end
 95       
 96         return length
 97       end
 98     end
 99 
100     # Register a cuecat scanner with the Scanner Registry
101     Registry.push(CueCat.new())
102 
103   end
104 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!