class Sawmill::RecordProcessor::FilterByAttributes

A record filter that checks attribute values.

This is a boolean processor, so it merely returns true or false based on the filter result. Use this in conjunction with an If processor to actually perform other actions based on the result.

Public Class Methods

new(attributes_) click to toggle source

Create a new filter. Pass the attribute names and values to check as a hash.

# File lib/sawmill/record_processor/filter_by_attributes.rb, line 54
def initialize(attributes_)
  @attributes = {}
  attributes_.each{ |key_, value_| @attributes[key_.to_s] = value_ }
end

Public Instance Methods

extra_entry(entry_) click to toggle source
# File lib/sawmill/record_processor/filter_by_attributes.rb, line 75
def extra_entry(entry_)
  false
end
finish() click to toggle source
# File lib/sawmill/record_processor/filter_by_attributes.rb, line 79
def finish
  nil
end
record(record_) click to toggle source
# File lib/sawmill/record_processor/filter_by_attributes.rb, line 60
def record(record_)
  @attributes.each do |key_, value_|
    record_value_ = record_.attribute(key_.to_s)
    case record_value_
    when ::Array
      return false unless record_value_.find{ |rval_| value_ === rval_ }
    when ::String
      return false unless value_ === record_value_
    when nil
      return false unless value_.nil?
    end
  end
  true
end