Class: ETL::Transform::DateToStringTransform

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

Overview

Transform a Date or Time to a formatted string instance

Instance Attribute Summary

Attributes inherited from Transform

#configuration, #control, #name

Instance Method Summary collapse

Methods inherited from Transform

benchmarks, transform

Constructor Details

#initialize(control, name, configuration = {}) ⇒ DateToStringTransform

Initialize the transformer.

Configuration options:

  • :format: A format passed to strftime. Defaults to %Y-%m-%d



9
10
11
12
# File 'lib/etl/transform/date_to_string_transform.rb', line 9

def initialize(control, name, configuration={})
  super
  @format = configuration[:format] || "%Y-%m-%d"
end

Instance Method Details

#transform(name, value, row) ⇒ Object

Transform the value using strftime



14
15
16
17
# File 'lib/etl/transform/date_to_string_transform.rb', line 14

def transform(name, value, row)
  return value unless value.respond_to?(:strftime)
  value.strftime(@format)
end