Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spec/std/csv/csv_parse_spec.cr
Original file line number Diff line number Diff line change
@@ -95,6 +95,14 @@ describe CSV do
sum.should eq(10)
end

it "does CSV.each_row with separator and quotes" do
sum = 0
CSV.each_row("1\t'2'\n3\t4\n", '\t', '\'') do |row|
sum += row.map(&.to_i).sum
end.should be_nil
sum.should eq(10)
end

it "gets row iterator" do
iter = CSV.each_row("1,2\n3,4\n")
iter.next.should eq(["1", "2"])
4 changes: 2 additions & 2 deletions src/csv.cr
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ class CSV
# ["three"]
# ```
def self.each_row(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
Parser.new(string_or_io).each_row do |row|
Parser.new(string_or_io, separator, quote_char).each_row do |row|
yield row
end
end
@@ -106,7 +106,7 @@ class CSV
# rows.next # => ["three"]
# ```
def self.each_row(string_or_io : String | IO, separator : Char = DEFAULT_SEPARATOR, quote_char : Char = DEFAULT_QUOTE_CHAR)
Parser.new(string_or_io).each_row
Parser.new(string_or_io, separator, quote_char).each_row
end

# Builds a CSV. This yields a `CSV::Builder` to the given block.

0 comments on commit d65ea1a

Please sign in to comment.