Permalink
Browse files

Query#to_csv

  • Loading branch information...
1 parent 2f45fba commit 967af6b57c586cc17c74a3810ea41c0456f08393 @paulrosania committed May 6, 2012
Showing with 14 additions and 0 deletions.
  1. +8 −0 lib/oculus/query.rb
  2. +6 −0 spec/query_spec.rb
View
@@ -56,6 +56,14 @@ def succeeded?
complete? && !error
end
+ def to_csv
+ CSV.generate do |csv|
+ results.each do |row|
+ csv << row
+ end
+ end
+ end
+
class << self
def create(attributes)
query = new(attributes)
View
@@ -137,4 +137,10 @@
query.execute(connection)
query.succeeded?.should be false
end
+
+ it "exports to CSV" do
+ query = Oculus::Query.new
+ query.results = [['id', 'name'], [1, 'Paul']]
+ query.to_csv.should == "id,name\n1,Paul\n"
+ end
end

0 comments on commit 967af6b

Please sign in to comment.