Class: Sycsvpro::ColumnFilter

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

Overview

Creates a new column filter

Direct Known Subclasses

ColumnTypeFilter

Instance Attribute Summary

Attributes inherited from Filter

#date_format, #filter, #pattern, #pivot, #types

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
20
21
22
23
24
# 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: '')
  object += " " if object =~ /;$/
  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
  if !filtered.last.nil? and filtered.last.empty?
    filtered.compact.join(';') + " " 
  else
    filtered.compact.join(';')
  end
end