Class: NcsNavigator::Warehouse::Filters::CodedAsMissingFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/ncs_navigator/warehouse/filters/coded_as_missing_filter.rb

Overview

Some source data sets include unnecessary placeholder records and values. This filter excludes the following variables and records:

  • Entire records whose ID is one of the common MDES error codes (-3, -4, -6, -7).

  • Foreign key values whose ID is one of those same MDES error codes.

  • Variable values which are not required and not coded whose value is one of these error codes (e.g., a comments field whose value is '-7').

If the :additional_codes option is passed to the constructor, those codes will be used in addition to the default list (i.e., -3, -4, -6, -7).

This filter may be used with or without instantiation.

Constant Summary collapse

DEFAULT_MISSING_CODES =
%w(-3 -4 -6 -7)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = nil, options = {}) ⇒ CodedAsMissingFilter

Returns a new instance of CodedAsMissingFilter.

Parameters:

  • configuration (Configuration) (defaults to: nil)
  • options (Hash<Symbol, Object>) (defaults to: {})

Options Hash (options):

  • :additional_codes (Array<String>)

    a list of other codes (beyond the defaults) which will also be treated as "missing" for the purposes of this filter.



46
47
48
49
50
51
# File 'lib/ncs_navigator/warehouse/filters/coded_as_missing_filter.rb', line 46

def initialize(configuration=nil, options={})
  @missing_codes = DEFAULT_MISSING_CODES.dup
  if options[:additional_codes]
    @missing_codes += options[:additional_codes]
  end
end

Instance Attribute Details

#missing_codesObject (readonly)

Returns the value of attribute missing_codes.



38
39
40
# File 'lib/ncs_navigator/warehouse/filters/coded_as_missing_filter.rb', line 38

def missing_codes
  @missing_codes
end

Class Method Details

.call(records) ⇒ Object



27
28
29
# File 'lib/ncs_navigator/warehouse/filters/coded_as_missing_filter.rb', line 27

def call(records)
  singleton.call(records)
end

Instance Method Details

#call(records) ⇒ Object



53
54
55
# File 'lib/ncs_navigator/warehouse/filters/coded_as_missing_filter.rb', line 53

def call(records)
  records.collect { |r| process(r) }.compact
end