Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,13 @@ def self.table(path, **options)
# +true+, CSV will strip string. The
# length of string must be 1.
#
# <b><tt>:undef</tt></b>:: When Converting encoding with
# "undef: :replace", you will replace
# character to replace.
#
# <b><tt>:replace</tt></b>:: Replace undef character to this value
#
#
# See CSV::DEFAULT_OPTIONS for the default settings.
#
# Options cannot be overridden in the instance methods for performance reasons,
Expand Down Expand Up @@ -936,7 +943,9 @@ def initialize(data,
write_converters: nil,
write_nil_value: nil,
write_empty_value: "",
strip: false)
strip: false,
undef: nil,
replace: nil)
Copy link
Member

@kou kou Apr 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to accept :undef and :replace in CVS#initialize?
It seems that we just need to accept them in CSV.open. Then we can remove them from options in CSV.open arguments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix the arguments in CSV.open.

raise ArgumentError.new("Cannot parse nil as CSV") if data.nil?

# create the IO object we will read from
Expand Down
8 changes: 8 additions & 0 deletions test/csv/interface/test_read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ def test_new_nil
end
end

def test_foreach_undef_replace
rows = []
CSV.foreach(@input.path, col_sep: "\t", row_sep: "\r\n", undef: :replace, replace: "*").each do |row|
rows << row
end
assert_equal(@rows, rows)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to new test data that fails without these new options.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a new test data.


def test_options_not_modified
options = {}.freeze
CSV.foreach(@input.path, options)
Expand Down