Skip to content

Commit

Permalink
Use separator and quote char in CSV#each_row method. Add a spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Su authored and asterite committed May 25, 2017
1 parent 0e73cf4 commit d65ea1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spec/std/csv/csv_parse_spec.cr
Expand Up @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions src/csv.cr
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit d65ea1a

Please sign in to comment.