Class: Pal::Operation::ProcessorContext

Inherits:
Object
  • Object
show all
Defined in:
lib/pal/operation/processor_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessorContext

Returns a new instance of ProcessorContext.



10
11
12
13
14
15
# File 'lib/pal/operation/processor_context.rb', line 10

def initialize
  @total_row_count = 0
  @current_file_row_count = 0
  @candidates = []
  @column_headers = {}
end

Instance Attribute Details

#candidatesObject

Returns the value of attribute candidates.



8
9
10
# File 'lib/pal/operation/processor_context.rb', line 8

def candidates
  @candidates
end

#column_headersObject

Returns the value of attribute column_headers.



8
9
10
# File 'lib/pal/operation/processor_context.rb', line 8

def column_headers
  @column_headers
end

#column_type_definitionsObject

Returns the value of attribute column_type_definitions.



8
9
10
# File 'lib/pal/operation/processor_context.rb', line 8

def column_type_definitions
  @column_type_definitions
end

#current_file_row_countObject

Returns the value of attribute current_file_row_count.



8
9
10
# File 'lib/pal/operation/processor_context.rb', line 8

def current_file_row_count
  @current_file_row_count
end

#total_row_countObject

Returns the value of attribute total_row_count.



8
9
10
# File 'lib/pal/operation/processor_context.rb', line 8

def total_row_count
  @total_row_count
end

Instance Method Details

#add_candidate(row) ⇒ Object



22
23
24
# File 'lib/pal/operation/processor_context.rb', line 22

def add_candidate(row)
  @candidates << row
end

#cast(column_header, value) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pal/operation/processor_context.rb', line 27

def cast(column_header, value)
  return value unless @column_type_definitions&.key?(column_header)

  case @column_type_definitions[column_header]["data_type"]
  when "string"
    value.to_s
  when "decimal"
    value.to_f
  when "integer"
    value.to_i
  when "date_time"
    DateTime.parse(value)
  when "date"
    Date.parse(value)
  when nil
    value
  else
    value
  end
end

#extract_column_headers(row) ⇒ Object

Parameters:

  • row (Array<String>)


18
19
20
# File 'lib/pal/operation/processor_context.rb', line 18

def extract_column_headers(row)
  row.each_with_index { |column, idx| @column_headers[column] = idx }
end