Sha256: 92df8b25d2ceef952f18c5d2e25936b8d6c5b55b653918c35304731d3e8c1cbc

Contents?: true

Size: 785 Bytes

Versions: 2

Compression:

Stored size: 785 Bytes

Contents

# exclude rows based on field = value

class Masticate::Exclude < Masticate::Base
  def configure(opts)
    standard_options(opts)

    @field = opts[:field] or raise "missing field to exclude"
    @value = opts[:value] or raise "missing value to exclude"

    # row-loading automatically strips leading & trailing whitespace and converts blanks to nils,
    # so when looking for blanks need to compare to nil instead of ''
    @value = nil if @value.empty?
  end

  def exclude(opts)
    execute(opts)
  end

  def crunch(row)
    if !@headers
      @headers = row
      @index = @headers.index(@field) or raise "Unable to find column '#{@field}' in headers"
      row
    elsif row
      if row[@index] == @value
        # exclude
      else
        row
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masticate-0.2.3 lib/masticate/exclude.rb
masticate-0.2.2 lib/masticate/exclude.rb