Class: Cure::Extract::VariableProcessor

Inherits:
BaseProcessor show all
Defined in:
lib/cure/extract/variable_processor.rb

Instance Attribute Summary collapse

Attributes inherited from BaseProcessor

#database_service

Instance Method Summary collapse

Constructor Details

#initialize(database_service, candidate_variables) ⇒ VariableProcessor

Returns a new instance of VariableProcessor.



16
17
18
19
20
21
22
23
24
# File 'lib/cure/extract/variable_processor.rb', line 16

def initialize(database_service, candidate_variables)
  super(database_service)

  @candidate_variables = candidate_variables
  @candidate_count = candidate_variables.length
  @processed = 0

  init_db
end

Instance Attribute Details

#candidate_variablesArray<Extraction::Variable> (readonly)

Returns variables.

Returns:

  • (Array<Extraction::Variable>)

    variables



14
15
16
# File 'lib/cure/extract/variable_processor.rb', line 14

def candidate_variables
  @candidate_variables
end

Instance Method Details

#candidate_rowsArray

Returns:

  • (Array)


44
45
46
# File 'lib/cure/extract/variable_processor.rb', line 44

def candidate_rows
  @candidate_rows ||= @candidate_variables.map { |v| v.location.last }
end

#process_row(row_idx, csv_row) ⇒ Object

Parameters:

  • row_idx (Integer)
  • csv_row (Array)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cure/extract/variable_processor.rb', line 28

def process_row(row_idx, csv_row)
  # Return if row is not in any variable OR if all candidates are processed.

  return if @candidate_count == @processed
  return unless candidate_rows.include?(row_idx)

  # Iterate over the NR's, if its inside those bounds, add it
  @candidate_variables.each do |cv|
    next unless cv.row_in_bounds?(row_idx)

    insert_record(:variables, [nil, cv.name, csv_row[cv.location.first]])
    @processed += 1
  end
end