Class: ETL::Transform::TrimTransform

Inherits:
Transform show all
Defined in:
lib/etl/transform/trim_transform.rb

Overview

Transform to trim string

Instance Attribute Summary

Attributes inherited from Transform

#configuration, #control, #name

Instance Method Summary (collapse)

Methods inherited from Transform

benchmarks, transform

Constructor Details

- (TrimTransform) initialize(control, name, configuration = {})

Configuration options:

  • :type: :left, :right or :both. Default is :both



7
8
9
10
# File 'lib/etl/transform/trim_transform.rb', line 7

def initialize(control, name, configuration={})
  super
  @type = (configuration[:type] || :both).to_sym
end

Instance Method Details

- (Object) transform(name, value, row)

Transform the value



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/etl/transform/trim_transform.rb', line 12

def transform(name, value, row)
  case @type
  when :left
    value.lstrip
  when :right
    value.rstrip
  when :both
    value.strip
  else
    raise "Trim type, if specified, must be :left, :right or :both"
  end
end