Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Query#to_csv

  • Loading branch information...
commit 967af6b57c586cc17c74a3810ea41c0456f08393 1 parent 2f45fba
@paulrosania authored
Showing with 14 additions and 0 deletions.
  1. +8 −0 lib/oculus/query.rb
  2. +6 −0 spec/query_spec.rb
View
8 lib/oculus/query.rb
@@ -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
6 spec/query_spec.rb
@@ -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.
Something went wrong with that request. Please try again.