diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/csv.rb | 10 | ||||
-rw-r--r-- | test/csv/test_table.rb | 6 |
3 files changed, 16 insertions, 4 deletions
@@ -1,3 +1,7 @@ +Sun Jan 31 14:33:00 2010 James Edward Gray II <jeg2@ruby-lang.org> + + * A bug fix for deleting blank Table rows from Andy Hartford. + Sun Jan 31 13:31:43 2010 wanabe <s.wanabe@gmail.com> * gc.c (obj_free): free rb_classext_t of eigenclass. [Bug #1392] diff --git a/lib/csv.rb b/lib/csv.rb index d44e4db744..c61e57c222 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -198,7 +198,7 @@ require "stringio" # class CSV # The version of the installed library. - VERSION = "2.4.5".freeze + VERSION = "2.4.6".freeze # # A CSV::Row is part Array and part Hash. It retains an order for the fields @@ -364,10 +364,12 @@ class CSV # or +nil+ if a pair could not be found. # def delete(header_or_index, minimum_index = 0) - if header_or_index.is_a? Integer # by index + if header_or_index.is_a? Integer # by index @row.delete_at(header_or_index) - else # by header - @row.delete_at(index(header_or_index, minimum_index)) + elsif i = index(header_or_index, minimum_index) # by header + @row.delete_at(i) + else + [ ] end end diff --git a/test/csv/test_table.rb b/test/csv/test_table.rb index e87f1b2545..b7c72b8fcb 100644 --- a/test/csv/test_table.rb +++ b/test/csv/test_table.rb @@ -321,6 +321,12 @@ class TestCSVTable < Test::Unit::TestCase END_RESULT end + def test_delete_with_blank_rows + data = "col1,col2\nra1,ra2\n\nrb1,rb2" + table = CSV.parse(data, :headers => true) + assert_equal(["ra2", nil, "rb2"], table.delete("col2")) + end + def test_delete_if ###################### ### Mixed/Row Mode ### |