Class: Cure::Extract::VariableProcessor
- Inherits:
-
BaseProcessor
- Object
- BaseProcessor
- Cure::Extract::VariableProcessor
- Defined in:
- lib/cure/extract/variable_processor.rb
Instance Attribute Summary collapse
-
#candidate_variables ⇒ Array<Extraction::Variable>
readonly
Variables.
Attributes inherited from BaseProcessor
Instance Method Summary collapse
- #candidate_rows ⇒ Array
-
#initialize(database_service, candidate_variables) ⇒ VariableProcessor
constructor
A new instance of VariableProcessor.
- #process_row(row_idx, csv_row) ⇒ Object
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_variables ⇒ Array<Extraction::Variable> (readonly)
Returns variables.
14 15 16 |
# File 'lib/cure/extract/variable_processor.rb', line 14 def candidate_variables @candidate_variables end |
Instance Method Details
#candidate_rows ⇒ 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
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 |