Class: Stockboy::Filter Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/stockboy/filter.rb

Overview

This class is abstract.

Filters can be any callable object that returns true or false. This abstract class is a helpful way to define a commonly used filter pattern.

Interface

Filter subclasses must define a filter method that returns true or false when called with the record context.

Examples:

class Bouncer < Stockboy::Filter
  def initialize(age)
    @age = age
  end
  def filter(input_context, output_context)
    input_context["RawAge"].empty? or output_context.age < @age
  end
end

Stockboy::Filters.register(:bouncer, Bouncer.new(19))
filter :under_age, :bouncer # in job template

Stockboy::Filters.register(:check_id, Bouncer)
filter :under_age, :bouncer, 19 # in job template

Direct Known Subclasses

Stockboy::Filters::MissingEmail

Instance Method Summary collapse

Instance Method Details

#call(raw_context, translated_context) ⇒ Boolean

Return true to capture a filtered record, false to pass it on

Parameters:

  • raw_context (SourceRecord)

    Unmapped source fields with Hash-like access field names (e.g. input["RawField"]) or raw values on mapped attributes as methods (e.g. input.email)

  • translated_context (MappedRecord)

    Mapped and translated fields with access to attributes as methods (output.email)

Returns:

  • (Boolean)


44
45
46
# File 'lib/stockboy/filter.rb', line 44

def call(raw_context, translated_context)
  return !!filter(raw_context, translated_context)
end