Class: Aspire::Enumerator::ReportEnumerator

Inherits:
Base
  • Object
show all
Defined in:
lib/aspire/enumerator/report_enumerator.rb

Overview

Enumerates rows from an exported Aspire report CSV (All Lists, All User Profiles etc.) with optional filtering

Instance Attribute Summary collapse

Attributes inherited from Base

#yielder

Instance Method Summary collapse

Methods inherited from Base

#enumerator

Constructor Details

#initialize(file = nil, filters = nil) ⇒ void

Initialises a new ListReport instance

Parameters:

  • file (String) (defaults to: nil)

    the filename of the report

  • filters (Array<Proc>) (defaults to: nil)

    a list of filters to select rows for processing. Each proc accepts a parsed row from the CSV file and returns true to accept it or false to reject it. All filters must return true for the row to be yielded.



26
27
28
29
# File 'lib/aspire/enumerator/report_enumerator.rb', line 26

def initialize(file = nil, filters = nil)
  self.file = file
  self.filters = filters
end

Instance Attribute Details

#fileString

Returns the filename of the report.

Returns:

  • (String)

    the filename of the report



13
14
15
# File 'lib/aspire/enumerator/report_enumerator.rb', line 13

def file
  @file
end

#filtersArray<Proc>

Returns a list of filters to select rows for processing.

Returns:

  • (Array<Proc>)

    a list of filters to select rows for processing



17
18
19
# File 'lib/aspire/enumerator/report_enumerator.rb', line 17

def filters
  @filters
end

Instance Method Details

#enumerate(*_args, **_kwargs) ⇒ void

This method returns an undefined value.

Enumerates the report rows



33
34
35
36
37
# File 'lib/aspire/enumerator/report_enumerator.rb', line 33

def enumerate(*_args, **_kwargs)
  CSV.foreach(file, converters: date_converter, headers: true, encoding: 'ISO-8859-1') do |row|
    yielder << row if filter(row)
  end
end