nitmetrics: moved CSVDocument from metrics_base to /lib
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 23 Jan 2013 19:52:20 +0000 (14:52 -0500)
committerJean Privat <jean@pryen.org>
Thu, 24 Jan 2013 22:38:07 +0000 (17:38 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/csv.nit [new file with mode: 0644]
src/metrics/inheritance_metrics.nit
src/metrics/metrics_base.nit

diff --git a/lib/csv.nit b/lib/csv.nit
new file mode 100644 (file)
index 0000000..71f28e5
--- /dev/null
@@ -0,0 +1,52 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# CSV output facilities
+module csv
+
+# A CSV document representation
+class CSVDocument
+       private var file: String
+       private var header: Array[String] = new Array[String]
+       private var lines: Array[Array[String]] = new Array[Array[String]]
+
+       init(file: String) do self.file = file
+
+       fun set_header(values: Object...) do
+               header.clear
+               for value in values do header.add(value.to_s)
+       end
+
+       fun add_line(values: Object...) do
+               if values.length != header.length then
+                       print "CSV error: header declares {header.length} columns, line contains {values.length} values"
+                       abort
+               end
+               var line = new Array[String]
+               for value in values do line.add(value.to_s)
+               lines.add(line)
+       end
+
+       redef fun to_s do
+               var str = header.join(";") + "\n"
+               for line in lines do str += line.join(";") + "\n"
+               return str
+       end
+
+       fun save do
+               var out = new OFStream.open(self.file)
+               out.write(self.to_s)
+               out.close
+       end
+end
\ No newline at end of file
index 951d164..5251216 100644 (file)
@@ -1104,5 +1104,4 @@ do
 end
 
 # TODO Third-Party metrics
-# TODO CSV generation
 # TODO gnu-plot generation
index 513d14d..058d47f 100644 (file)
@@ -18,6 +18,7 @@
 module metrics_base
 
 import modelbuilder
+import csv
 
 redef class ToolContext
 
@@ -174,42 +175,6 @@ private class CounterSorter[E: Object]
        redef fun compare(a,b) do return self.counter.map[a] <=> self.counter.map[b]
 end
 
-# Helper class to output metrics as CVS formatted files
-class CSVDocument
-       private var file: String
-       private var header: Array[String] = new Array[String]
-       private var lines: Array[Array[String]] = new Array[Array[String]]
-
-       init(file: String) do self.file = file
-
-       fun set_header(values: Object...) do
-               header.clear
-               for value in values do header.add(value.to_s)
-       end
-
-       fun add_line(values: Object...) do
-               if values.length != header.length then
-                       print "CSV error: header declares {header.length} columns, line contains {values.length} values"
-                       abort
-               end
-               var line = new Array[String]
-               for value in values do line.add(value.to_s)
-               lines.add(line)
-       end
-
-       redef fun to_s do
-               var str = header.join(";") + "\n"
-               for line in lines do str += line.join(";") + "\n"
-               return str
-       end
-
-       fun save do
-               var out = new OFStream.open(self.file)
-               out.write(self.to_s)
-               out.close
-       end
-end
-
 # Helper function to display n/d and handle division by 0
 fun div(n: Int, d: Int): String
 do