Class: Cure::Transformation::Transform
- Inherits:
-
Object
- Object
- Cure::Transformation::Transform
- Includes:
- Configuration, Helpers::FileHelpers, Log
- Defined in:
- lib/cure/transformation/transform.rb
Overview
Operational file for conducting transforms
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(candidates) ⇒ Transform
constructor
A new instance of Transform.
- #remove_system_columns(row) ⇒ Object
- #transform(row) ⇒ Hash
Methods included from Configuration
#config, #create_config, #register_config
Methods included from Helpers::FileHelpers
#clean_dir, #open_file, #read_file, #with_file, #with_temp_dir
Methods included from Log
#log_debug, #log_error, #log_info, #log_trace, #log_warn
Constructor Details
#initialize(candidates) ⇒ Transform
Returns a new instance of Transform.
22 23 24 |
# File 'lib/cure/transformation/transform.rb', line 22 def initialize(candidates) @candidates = candidates end |
Instance Attribute Details
#candidates ⇒ Array<Candidate>
19 20 21 |
# File 'lib/cure/transformation/transform.rb', line 19 def candidates @candidates end |
Instance Method Details
#remove_system_columns(row) ⇒ Object
46 47 48 49 |
# File 'lib/cure/transformation/transform.rb', line 46 def remove_system_columns(row) row.delete(:_id) row end |
#transform(row) ⇒ Hash
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cure/transformation/transform.rb', line 28 def transform(row) original_row = row.dup @candidates.each do |candidate| column = candidate.column.to_sym next unless row.key?(column) existing_value = row[column] next if existing_value.nil? && candidate.ignore_empty new_value = candidate.perform(existing_value, RowCtx.new(row, original_row: original_row)) # transform value row[column] = new_value end remove_system_columns(row) end |