Sha256: 5741a5c58bfcab11dbf46624b857d6a829605cf379ee8851763c9d828e06fe1b
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
# cook up a recipe # * single file as input # * recipe from a file # * multiple steps # * single output require "shellwords" class Masticate::Cook < Masticate::Base def initialize(filename) @filename = filename end def cook(opts) standard_options(opts) recipefile = opts[:recipe] or raise "missing recipe for cook" recipe = File.read(recipefile).lines standard_options(opts) steps = recipe.map do |step| # puts step argv = Shellwords.split(step) masticator = Masticate::MyOptionParser.new command, options = masticator.parse(argv) masticator.prepare(command, options) end @output_count = 0 headers = nil with_input do |input| while line = get row = CSV.parse_line(line, csv_options) steps.each do |step| row = step.crunch(row) if row end emit(row) if row end end steps.each do |step| step.crunch(nil) {|row| emit(row)} end @output.close if opts[:output] { :input_count => @input_count, :output_count => @output_count } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
masticate-0.2.3 | lib/masticate/cook.rb |
masticate-0.2.2 | lib/masticate/cook.rb |
masticate-0.2.1 | lib/masticate/cook.rb |