Class: Cure::Transformation::Transform

Inherits:
Object
  • Object
show all
Includes:
FileHelpers, Log
Defined in:
lib/cure/transformation/transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileHelpers

#clean_dir, #read_file, #with_file, #with_temp_dir

Methods included from Log

#log_debug, #log_error, #log_info, #log_warn

Constructor Details

#initialize(candidates) ⇒ Transform

Returns a new instance of Transform.

Parameters:



17
18
19
# File 'lib/cure/transformation/transform.rb', line 17

def initialize(candidates)
  @candidates = candidates
end

Instance Attribute Details

#candidatesArray<Candidate>

Returns:



14
15
16
# File 'lib/cure/transformation/transform.rb', line 14

def candidates
  @candidates
end

Instance Method Details

#extract_from_contents(file_contents) ⇒ TransformContext

Parameters:

  • file_contents (String)

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cure/transformation/transform.rb', line 30

def extract_from_contents(file_contents)
  ctx = TransformContext.new
  parse_content(ctx, file_contents, header: :none) do |row|
    if ctx.row_count == 1
      ctx.extract_column_headers(row)
      next
    end

    row = transform(ctx.column_headers, row)
    ctx.add_transformed_row(row)
  end

  ctx
end

#extract_from_file(csv_file_location) ⇒ TransformContext

Parameters:

  • csv_file_location (String)

Returns:



23
24
25
26
# File 'lib/cure/transformation/transform.rb', line 23

def extract_from_file(csv_file_location)
  file_contents = read_file(csv_file_location)
  extract_from_contents(file_contents)
end