class Morfo::Base

Public Class Methods

field(*field_path) click to toggle source
# File lib/morfo.rb, line 10
def self.field *field_path
  act = Morfo::Actions::Field.new(field_path, mapping_actions)
  mapping_actions[field_path] = act
  act
end
morf(input, options = {}) click to toggle source
# File lib/morfo.rb, line 16
def self.morf input, options = {}
  input.map { |row| morf_single(row, options) }
end
morf_single(input, options = {}) click to toggle source
# File lib/morfo.rb, line 20
def self.morf_single input, options = {}
  output = {}
  mapping_actions.each do |field_path, action|
    output.deeper_merge!(store_value(action.execute(input), field_path, options))
  end
  output
end

Private Class Methods

mapping_actions() click to toggle source
# File lib/morfo.rb, line 29
def self.mapping_actions
  @actions ||= {}
end
store_value(value, to, options) click to toggle source
# File lib/morfo.rb, line 33
def self.store_value value, to, options
  return {} if value.nil? && !options[:include_nil_values]

  to.reverse.inject({}) do |hash, key|
    if hash.empty?
      hash.merge!(key => value)
    else
      { key => hash }
    end
  end
end