Permalink
Browse files

Adding Andy's fix for deleting from blank Table rows.

git-svn-id: svn+ssh://rubyforge.org/var/svn/fastercsv/trunk@73 e365412f-4209-0410-a6b9-d67c64ae9f52
  • Loading branch information...
1 parent 1aacf64 commit 6e7816a0433c92dc5d57934c0c783814dbddbe21 @JEG2 committed Jan 7, 2010
Showing with 16 additions and 4 deletions.
  1. +4 −0 CHANGELOG
  2. +6 −4 lib/faster_csv.rb
  3. +6 −0 test/tc_table.rb
View
@@ -2,6 +2,10 @@
Below is a complete listing of changes for each revision of FasterCSV.
+== 1.5.1
+
+* A bug fix for deleting blank Table rows from Andy Hartford.
+
== 1.5.0
* The main parser has been rewritten by Timothy Elliott to avoid big input
View
@@ -82,7 +82,7 @@
#
class FasterCSV
# The version of the installed library.
- VERSION = "1.5.0".freeze
+ VERSION = "1.5.1".freeze
#
# A FasterCSV::Row is part Array and part Hash. It retains an order for the
@@ -249,10 +249,12 @@ def push(*args)
# returned, 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
View
@@ -319,6 +319,12 @@ def test_delete
END_RESULT
end
+ def test_delete_with_blank_rows
+ data = "col1,col2\nra1,ra2\n\nrb1,rb2"
+ table = FasterCSV.parse(data, :headers => true)
+ assert_equal(["ra2", nil, "rb2"], table.delete("col2"))
+ end
+
def test_delete_if
######################
### Mixed/Row Mode ###

0 comments on commit 6e7816a

Please sign in to comment.