Class: Kiba::Extend::Transforms::DateValue::ForceDayPrecision
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::DateValue::ForceDayPrecision
- Defined in:
- lib/kiba/extend/transforms/date_value/force_day_precision.rb
Overview
The current iteration of this transform has very limited date parsing intelligence. We recommend that you set the target field to a new field, so that you can check the output against the original values.
The current iteration interprets a date like “2/4/2001” as February 4, not April 2. This is not currently configurable.
The current iteration of this transform will handle 2-digit years unpredictably
Pads out year or year-month date values to year-month-day values in ISO 8601 format (yyyy-mm-dd).
If a date cannot be converted to a valid ISO 8601 date, the target field will be nil, and “error” will be written to the warnfield.
If a date could be converted, but via an unpredictable means (e.g.
the default Ruby Date.parse functionality), then the converted
valid ISO 8601 date is written to target, and “warn” is written to
the warnfield.
Instance Method Summary collapse
-
#initialize(source:, target:, warnfield: :date_warning, month: 1, day: 1) ⇒ ForceDayPrecision
constructor
A new instance of ForceDayPrecision.
-
#process(row) ⇒ Object
Constructor Details
#initialize(source:, target:, warnfield: :date_warning, month: 1, day: 1) ⇒ ForceDayPrecision
Returns a new instance of ForceDayPrecision.
92 93 94 95 96 97 98 99 |
# File 'lib/kiba/extend/transforms/date_value/force_day_precision.rb', line 92 def initialize(source:, target:, warnfield: :date_warning, month: 1, day: 1) @source = source @target = target @warnfield = warnfield @month = month @day = day end |
Instance Method Details
#process(row) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/kiba/extend/transforms/date_value/force_day_precision.rb', line 101 def process(row) [target, warnfield].each { |f| row[f] = nil } val = row[source] return row if val.blank? write_target_and_warnings(get_result(val), row) row end |