Class: Cure::Transformation::Transform
- Inherits:
-
Object
- Object
- Cure::Transformation::Transform
- Includes:
- FileHelpers, Log
- Defined in:
- lib/cure/transformation/transform.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #extract_from_contents(file_contents) ⇒ TransformContext
- #extract_from_file(csv_file_location) ⇒ TransformContext
-
#initialize(candidates) ⇒ Transform
constructor
A new instance of Transform.
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.
17 18 19 |
# File 'lib/cure/transformation/transform.rb', line 17 def initialize(candidates) @candidates = candidates end |
Instance Attribute Details
#candidates ⇒ Array<Candidate>
14 15 16 |
# File 'lib/cure/transformation/transform.rb', line 14 def candidates @candidates end |
Instance Method Details
#extract_from_contents(file_contents) ⇒ TransformContext
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
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 |