Sha256: f975f209338c64af916e84b2679a7eed871f1a20e0f8fe376cfa1930d25a60ac

Contents?: true

Size: 718 Bytes

Versions: 4

Compression:

Stored size: 718 Bytes

Contents

require 'csv'

module ReVIEW
  module Retrovert
    class Utils
      class << self

        # tsv to csv
        def Tsv2Csv(infile, outfile)
          File.open(infile, 'r') do |file|
            CSV.open(outfile, 'w') do |csv|
              file.each_line do |line|
                csv << line.chomp.split(/\t+/)
              end
            end
          end
        end

        def NormalizeCSVArray(ar)
          ar&.each do |c|
            c.gsub!(/\A"|"\z/, '')
            c.gsub!(/^\s*/, '')
            c.gsub!(/[\r\n]/, '')
          end
          ar
        end

        def GenerateTsv(c)
          CSV.generate_line(Utils::NormalizeCSVArray(c), col_sep: "\t")
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
review-retrovert-0.9.11 lib/review/retrovert/utils.rb
review-retrovert-0.9.10 lib/review/retrovert/utils.rb
review-retrovert-0.9.9 lib/review/retrovert/utils.rb
review-retrovert-0.9.8 lib/review/retrovert/utils.rb