Sha256: 2f62edb58d399847a1afb2467d14694d1d39f6ea89d813bcb137b7037f191af5
Contents?: true
Size: 1.07 KB
Versions: 25
Compression:
Stored size: 1.07 KB
Contents
module Workarea module Configuration class Params def initialize(params) @params = params end def to_h Admin.definition.fields.each_with_object({}) do |field, memo| next unless @params.key?(field.key) value = @params[field.key] formatted_value = if value.present? && respond_to?(field.type) send(field.type, field, value) else value end memo[field.key] = if formatted_value.blank? && !field.allow_blank? field.default else formatted_value end end end def array(field, value) Array.wrap(CSV.parse(value).first).map(&:strip) end def hash(field, value) value.each_slice(2) .to_h .reject { |k, v| k.blank? || v.blank? } .transform_values { |v| field.values_type_class.mongoize(v) } end def duration(field, value) value.first.to_i.send(value.last.to_sym) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems