class XporterOnDemand::Result::Serialiser

Constants

FORMATTERS
FORMAT_REGISTRY

Public Class Methods

serialise(attributes) click to toggle source
# File lib/xporter_on_demand/result/serialiser.rb, line 31
def self.serialise(attributes)
  object_array = attributes.map do |attribute, value|
    key = attribute.underscore
    format = get_format(key)

    [key, FORMATTERS[format].call(value)]
  end
  object_array.to_h
end

Private Class Methods

get_format(key) click to toggle source
# File lib/xporter_on_demand/result/serialiser.rb, line 42
def self.get_format(key)
  if key =~ /_ids\z/
    :csv
  elsif key =~ /(_?date\z|(start|end)\z)/
    :date
  elsif key =~ /_date_time\z/
    :date_time
  elsif key =~ /\Ais_/
    :boolean
  else
    FORMAT_REGISTRY[key.to_sym][:type]
  end
end