Jldrill Git C0 Coverage Information - RCov

lib/jldrill/model/moji/Radical.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/jldrill/model/moji/Radical.rb 126 102
98.41%
98.04%

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 'jldrill/model/DataFile'
2 
3 module JLDrill
4 
5     # A radical (part of a kanji character).
6 	class Radical
7 
8         RADICAL_RE = Regexp.new('(\S)\t(\S*)\t(\S*)\t([^\t]*)\t(\S+)?', nil, 'U')
9         TO_A_RE = Regexp.new("",nil,'U')
10 	
11 		attr_reader :radical, :reading, :altGlyphs, :meaning, :contents
12 		attr_writer :radical, :reading, :altGlyphs, :meaning, :contents
13 
14 		def initialize(radical, reading, altGlyphs, meaning, contents)
15 			@radical = radical
16 			@reading = reading
17 			@altGlyphs = altGlyphs
18 			@meaning = meaning
19 			@contents = contents
20 		end
21 		
22 		def Radical.splitChars(string)
23 			if !string.nil?
24 			    string.split(TO_A_RE)
25 			else
26 			    []
27 			end
28 	    end
29 		
30 		def Radical.parse(string)
31 			entry = nil
32 
33 			if string =~ RADICAL_RE
34 				radical = $1
35 				altGlyphs = Radical.splitChars($2)
36 				reading = $3
37 				meaning = $4
38 				contents = Radical.splitChars($5)
39 				entry = Radical.new(radical, reading, altGlyphs,
40 				                    meaning, contents)
41 			end
42 			entry
43 		end
44 		
45 		def eql?(radical)
46 		    self.to_s == radical.to_s
47 		end
48 		
49 		def to_s
50 		    retVal = @radical
51 		    if @altGlyphs.size > 0
52 		        retVal += "(" + @altGlyphs.join(",") + ")"
53 		    end
54 		    retVal += "   " + @reading + " - " + @meaning
55             retVal		    
56 		end
57 
58 	end
59 
60 	class RadicalList < Array
61 	
62 		def RadicalList.fromString(string)
63 			file = RadicalList.new
64 			string.each_line do |line|
65 				file.parse(line)
66 			end
67 			file
68 		end
69 		
70 		def RadicalList.fromFile(filename)
71 			file = RadicalList.new
72 			IO.foreach(filename) do |line|
73 				file.parse(line)			
74 			end
75 			file
76 		end
77 
78 		def parse(string)
79 			entry = Radical.parse(string)
80 			if(!entry.nil?)
81 				self.push(entry)
82 			end
83 		end
84 		
85 		def includesChar?(radicalChar)
86 		    item = self.find do |rad|
87 		        rad.radical == radicalChar
88 		    end
89 		    return !item.nil?
90 		end
91 		
92 		def radicals(character)
93 			retVal = RadicalList.new
94 			self.each do |entry|
95 				if entry.radical == character || 
96 				  entry.contents.include?(character)
97 					retVal.push(entry)
98 				end
99 			end
100 			retVal
101 		end
102 		
103 		def to_s
104 		    self.join("\n") + "\n"
105 		end
106 	end
107 
108     class RadicalFile < DataFile
109         attr_reader :radicalList
110         attr_writer :radicalList
111 
112         def initialize
113             super
114             @radicalList = RadicalList.new
115         end
116 
117         def dataSize
118             @radicalList.size
119         end
120 
121         def parser
122             @radicalList
123         end
124     end
125 
126 end

Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8