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
Expand Up @@ -26,24 +26,25 @@ def initialize(xml)




# Outputs in Comma Seperated Values format # Outputs in Comma Seperated Values format
def to_csv(format = :long) def to_csv(format = :short)
output = '' output = ''
columns = [] columns = []


# only output # only output
case format case format
when :long when :long

[@id, @updated, @title].each { |c| columns << c } [@id, @updated, @title].each { |c| columns << c }
end end


# output all dimensions # 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 # 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) output = CSV.generate_line(columns)
return output
end end




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


end end


end end
13 changes: 7 additions & 6 deletions lib/gattica/data_set.rb
Expand Up @@ -21,21 +21,22 @@ def initialize(xml)
# #
# == Parameters: # == Parameters:
# +format=:long+:: Adds id, updated, title to output columns # +format=:long+:: Adds id, updated, title to output columns
def to_csv(format=:long) def to_csv(format=:short)
output = '' output = ''
columns = [] columns = []
case format case format
when :long when :long
["id", "updated", "title"].each { |c| columns << c } ["id", "updated", "title"].each { |c| columns << c }
end end
unless @points.empty? # if there was at least one result unless @points.empty? # if there was at least one result
@points.first.dimensions.map {|d| d.key}.each { |c| columns << c } @points.first.dimensions.map {|d| d.keys.first}.each { |c| columns << c }
@points.first.metrics.map {|m| m.key}.each { |c| columns << c } @points.first.metrics.map {|m| m.keys.first}.each { |c| columns << c }
end end
output = CSV.generate_line(columns) + "\n" output = CSV.generate_line(columns)
@points.each do |point| @points.each do |point|
output += point.to_csv(format) + "\n" output += point.to_csv(format)
end end
output
end end


def to_yaml def to_yaml
Expand All @@ -49,4 +50,4 @@ def to_yaml


end end


end end

0 comments on commit 0c52ab8

Please sign in to comment.