Sha256: 207f576fce52b8b6e72dc7297c09d9613621b5256e182925ea728c24b61e6af5
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
# Part of the Optimus package for managing E-Prime data # # Copyright (C) 2008 Board of Regents of the University of Wisconsin System # # Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain # Imaging and Behavior, University of Wisconsin - Madison module Eprime module Transformers # Implements a row-wise filter for eprime data. # Right now it requires a proc; I'll do something better with a little # DSL later. class RowFilter include Enumerable def initialize(data, filter) @data = data @filter = filter end def to_eprime_data Eprime::Data.new().merge!(self) end def each @data.each do |row| yield row if match?(row) end end def match?(row) if @filter.is_a? Proc return @filter.call(row) elsif @filter.is_a? Array # @filter will be of the form [col_name, comparator, [value]] # only 'equals' is supported for comparators if @filter[1].downcase != 'equals' raise ArgumentError.new('Only equals is supported in filtering') end return row[@filter[0]].to_s == @filter[2].to_s end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
optimus-ep-0.5.5 | lib/transformers/row_filter.rb |
optimus-ep-0.5.6 | lib/transformers/row_filter.rb |
optimus-ep-0.6.0 | lib/transformers/row_filter.rb |