Sha256: 5bfcd75f13eb1555e7899124cdc23207f1dbfe54f7054d9a2cb66c29b794fa6f
Contents?: true
Size: 737 Bytes
Versions: 2
Compression:
Stored size: 737 Bytes
Contents
# extract subset of columns from CSV require "csv" class Masticate::Plucker < Masticate::Base def pluck(opts) standard_options(opts) fields = opts[:fields] or raise "missing fields to pluck" @output_count = 0 headers = nil with_input do |input| while line = get row = CSV.parse_line(line, csv_options) if !headers headers = row indexes = fields.map {|f| headers.index(f) or raise "Unable to find column '#{f}'"} emit(fields.to_csv) else emit(indexes.map {|i| row[i]}.to_csv) if row end end end @output.close if opts[:output] { :input_count => input_count, :output_count => @output_count } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
masticate-0.1.3 | lib/masticate/plucker.rb |
masticate-0.1.1 | lib/masticate/plucker.rb |