lib/gattica/data_set.rb in cannikin-gattica-0.3.1 vs lib/gattica/data_set.rb in cannikin-gattica-0.3.3
- old
+ new
@@ -23,27 +23,24 @@
# (total_results, start_date) and just output the data from the points
def to_csv(format = :long)
# build the headers
output = ''
-
+ columns = []
+
# only show the nitty gritty details of id, updated_at and title if requested
case format
when :long
- output = '"id","updated","title",'
+ ["id", "updated", "title"].each { |c| columns << c }
end
unless @points.empty? # if there was at least one result
- output += @points.first.dimensions.collect do |dimension|
- "\"#{dimension.key.to_s}\""
- end.join(',')
- output += ','
- output += @points.first.metrics.collect do |metric|
- "\"#{metric.key.to_s}\""
- end.join(',')
- output += "\n"
+ @points.first.dimensions.map {|d| d.key}.each { |c| columns << c }
+ @points.first.metrics.map {|m| m.key}.each { |c| columns << c }
end
+ output = CSV.generate_line(columns) + "\n"
+
# get the data from each point
@points.each do |point|
output += point.to_csv(format) + "\n"
end
\ No newline at end of file