ruby-changes:14665
From: jeg2 <ko1@a...>
Date: Sun, 31 Jan 2010 14:34:33 +0900 (JST)
Subject: [ruby-changes:14665] Ruby:r26516 (trunk): * A bug fix for deleting blank Table rows from Andy Hartford.
jeg2 2010-01-31 14:34:17 +0900 (Sun, 31 Jan 2010) New Revision: 26516 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26516 Log: * A bug fix for deleting blank Table rows from Andy Hartford. Modified files: trunk/ChangeLog trunk/lib/csv.rb trunk/test/csv/test_table.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 26515) +++ ChangeLog (revision 26516) @@ -1,3 +1,7 @@ +Sun Jan 31 14:33:00 2010 James Edward Gray II <jeg2@r...> + + * A bug fix for deleting blank Table rows from Andy Hartford. + Sun Jan 31 13:31:43 2010 wanabe <s.wanabe@g...> * gc.c (obj_free): free rb_classext_t of eigenclass. [Bug #1392] Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 26515) +++ lib/csv.rb (revision 26516) @@ -198,7 +198,7 @@ # 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 @@ # 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 Index: test/csv/test_table.rb =================================================================== --- test/csv/test_table.rb (revision 26515) +++ test/csv/test_table.rb (revision 26516) @@ -321,6 +321,12 @@ 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 ### -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/