Permalink
Browse files

Merge pull request #4 from vgololobov/master

CSV export fix
  • Loading branch information...
2 parents 492c432 + 0c52ab8 commit 0b92ea67a8e4545b3b9d17d5891f1357d157fc29 Chris Le committed Jan 10, 2012
Showing with 14 additions and 12 deletions.
  1. +7 −6 lib/gattica/data_point.rb
  2. +7 −6 lib/gattica/data_set.rb
@@ -26,24 +26,25 @@ def initialize(xml)
# Outputs in Comma Seperated Values format
- def to_csv(format = :long)
+ def to_csv(format = :short)
output = ''
columns = []
# only output
case format
when :long
+
[@id, @updated, @title].each { |c| columns << c }
end
# output all dimensions
- @dimensions.map {|d| d.value}.each { |c| columns << c }
-
+
+ @dimensions.map {|d| d.values.first}.each { |c| columns << c }
# output all metrics
- @metrics.map {|m| m.value}.each { |c| columns << c }
+ @metrics.map {|m| m.values.first}.each { |c| columns << c }
output = CSV.generate_line(columns)
- return output
+
end
@@ -57,4 +58,4 @@ def to_yaml
end
-end
+end
@@ -21,21 +21,22 @@ def initialize(xml)
#
# == Parameters:
# +format=:long+:: Adds id, updated, title to output columns
- def to_csv(format=:long)
+ def to_csv(format=:short)
output = ''
columns = []
case format
when :long
["id", "updated", "title"].each { |c| columns << c }
end
unless @points.empty? # if there was at least one result
- @points.first.dimensions.map {|d| d.key}.each { |c| columns << c }
- @points.first.metrics.map {|m| m.key}.each { |c| columns << c }
+ @points.first.dimensions.map {|d| d.keys.first}.each { |c| columns << c }
+ @points.first.metrics.map {|m| m.keys.first}.each { |c| columns << c }
end
- output = CSV.generate_line(columns) + "\n"
+ output = CSV.generate_line(columns)
@points.each do |point|
- output += point.to_csv(format) + "\n"
+ output += point.to_csv(format)
end
+ output
end
def to_yaml
@@ -49,4 +50,4 @@ def to_yaml
end
-end
+end

0 comments on commit 0b92ea6

Please sign in to comment.