Class: Sycsvpro::ColumnFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/sycsvpro/column_filter.rb

Overview

Creates a new column filter

Instance Attribute Summary

Attributes inherited from Filter

#date_format, #filter, #pattern, #pivot

Instance Method Summary collapse

Methods inherited from Filter

#has_filter?, #initialize, #method_missing, #pivot_each_column

Constructor Details

This class inherits a constructor from Sycsvpro::Filter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sycsvpro::Filter

Instance Method Details

#process(object, options = {}) ⇒ Object

Processes the filter and returns the values that respect the filter



10
11
12
13
14
15
16
17
18
19
# File 'lib/sycsvpro/column_filter.rb', line 10

def process(object, options={})
  return nil if object.nil? or object.empty?
  object = object.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
  return object if filter.empty? and pivot.empty?
  filtered = object.split(';').values_at(*filter.flatten.uniq)
  pivot_each_column(object.split(';')) do |column, match|
    filtered << column if match
  end
  filtered.compact.join(';')
end