class Workable::Transformation

Public Class Methods

new(mappings) click to toggle source
# File lib/workable/transformation.rb, line 3
def initialize(mappings)
  @mappings = mappings || {}
end

Public Instance Methods

apply(mapping, data) click to toggle source

selects transformation strategy based on the inputs @param transformation [Method|Proc|nil] the transformation to perform @param data [Hash|Array|nil] the data to transform @return [Object|nil]

results of the transformation if given, raw data otherwise
# File lib/workable/transformation.rb, line 12
def apply(mapping, data)
  transformation = @mappings[mapping]
  return data unless transformation

  case data
  when nil
    data
  when Array
    data.map { |datas| transformation.call(datas) }
  else
    transformation.call(data)
  end
end