Re: Ruby Quiz is Back - Challenge #1 - Read Comma-Separated Values (CSV) from the "Real World"
Dave Burt <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAPcy0xBH5J66nb_qp2qmA=RJNM62KJEAxnB9xXYA5yUHXxx5NA@mail.gmail.com> |
Dear Quizmaster,
Are there general guidelines like for the first Ruby Quiz (
http://rubyquiz.com/)?
Anyway, here is my brief entry.
#
# A simple solution using core String and Regexp features.
#
def parse( txt )
txt.each_line.map do |line|
next if line =~ /^#/ || line =~ /^\s+$/
line.strip.split(/\s*,\s*/, -1).map do |field|
field.sub(/^(['"])(.*)\1$/, '\\2')
end
end.compact
end
Cheers,
Dave
On Mon, Oct 29, 2018 at 2:53 AM Gerald Bauer <[email protected]> wrote:
> Hello,
> sorry for the false start of the Ruby Quiz. The Ruby Quiz is now
> back for real.
>
> Challenge #1 - Read Comma-Separated Values (CSV) from the "Real World"
>
> Let's use the test.csv [1] file from Apache Commons CSV Reader.
> The challenge: Code a parse method that passes the RubyQuizTest :-).
> Start from scratch or, yes, use any library / gem you can find.
>
> ```
> def parse( txt )
> ...
> end
> ```
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>