On Sun, Feb 23, 2014 at 4:30 PM, Arup Rakshit <lists / ruby-forum.com> wrote:
> Here is a CSV data in one of my file has :
>
> "DE","Klasse","Deutsch", "x"
> "EN","Class","Carpenter",
> "DE","Klasse","Mathe",
> ,,,
>
> Code I wrote :
>
> require 'csv'
>
> input_file_path = File.expand_path('input.csv',File.dirname(__FILE__))
> output_file_path = File.expand_path('output.csv',File.dirname(__FILE__))
>
> option = { :skip_blanks => true,
>            :quote_char => "\'",
>            :converters => CSV::Converters[:remove_quotes] = lambda do
> |field|
>              field.to_s.tr('"','')
>            end
>          }
>
> CSV.open(output_file_path,'w',:force_quotes => true) do |out_row|
>   CSV.foreach(input_file_path, option) do |in_row|
>     row_to_add = in_row.reject(&:empty?)
>     out_row.puts row_to_add unless row_to_add.empty? or
> row_to_add.last[/^\s+x$/]
>   end
> end
>
> **output** ( also expected )
>
> "EN","Class","Carpenter"
> "DE","Klasse","Mathe"
>
> But my question is -
>
> How can I skip lines like **,,,** using option **:skip_lines** (
> http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html#method-c-new)

The :skip_lines option receives an object that responds to match (for
example a Regex). The lines for which this object returns false are
skipped. For example:

:skip_lines => /,,,/

(untested)

Jesus.