Skip to content

Commit

Permalink
Fixed csv export. Set csv export default fotmat to short (long contai…
Browse files Browse the repository at this point in the history
…ns garbage, and should be fixed)
  • Loading branch information
vgololobov committed Jan 10, 2012
1 parent 492c432 commit 0c52ab8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions lib/gattica/data_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -57,4 +58,4 @@ def to_yaml

end

end
end
13 changes: 7 additions & 6 deletions lib/gattica/data_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,4 +50,4 @@ def to_yaml

end

end
end

0 comments on commit 0c52ab8

Please sign in to comment.