Re: Ruby Quiz is Back - Challenge #1 - Read Comma-Separated Values (CSV) from the "Real World"

"Frank J. Cameron" <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
> Challenge #1 - Read Comma-Separated Values (CSV) from the "Real World"

$ ruby lib/1.rb
Run options: --seed 19056
# Running:
.
Finished in 0.002289s, 436.9176 runs/s, 436.9176 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

$ cat lib/1.rb
require_relative '../test/1.rb'
class RubyQuizTest
  def parse(text)
    text.lines.map do |line|
      next if line.match(/^\s*$|#/)
      line.strip.split(/\s*,\s*/, -1)
    end.compact.map do |cells|
      cells.map do |cell|
        cell.match(/"(.*)"/) ? $1 : cell
      end
    end
  end
end
RubyQuizTest.new('fjc')



Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.