Permalink
Browse files

Adding support for :write_headers => false to Table.to_csv().

  • Loading branch information...
1 parent cb34834 commit 529effcef02888f19c6fd772add25c98af24ff71 @JEG2 committed Feb 19, 2010
Showing with 8 additions and 1 deletion.
  1. +1 −0 CHANGELOG
  2. +5 −1 lib/faster_csv.rb
  3. +2 −0 test/tc_table.rb
View
@@ -5,6 +5,7 @@ Below is a complete listing of changes for each revision of FasterCSV.
== 1.5.2
* A bug fix to allow IO Exceptions to reach the calling code from Moses Hohman.
+* Added support for <tt>:write_headers => false</tt> to Table.to_csv().
== 1.5.1
View
@@ -704,8 +704,12 @@ def to_a
# Returns the table as a complete CSV String. Headers will be listed first,
# then all of the field rows.
#
+ # This method assumes you want the Table.headers(), unless you explicitly
+ # pass <tt>:write_headers => false</tt>.
+ #
def to_csv(options = Hash.new)
- @table.inject([headers.to_csv(options)]) do |rows, row|
+ wh = options.fetch(:write_headers, true)
+ @table.inject(wh ? [headers.to_csv(options)] : [ ]) do |rows, row|
if row.header_row?
rows
else
View
@@ -251,6 +251,8 @@ def test_to_csv
# with options
assert_equal( csv.gsub(",", "|").gsub("\n", "\r\n"),
@table.to_csv(:col_sep => "|", :row_sep => "\r\n") )
+ assert_equal( csv.to_a[1..-1].join,
+ @table.to_csv(:write_headers => false) )
# with headers
assert_equal(csv, @header_table.to_csv)

0 comments on commit 529effc

Please sign in to comment.