module RailsConnector class ObjParamsParser def initialize(host, port) @host = host @port = port end def parse(obj, params) raise "Required parameter 'obj' is missing." unless params.present? raise "Parameter 'obj' is not a hash." unless params.is_a?(Hash) if obj convert_params(params, obj) if widget_pool_params = params['_widget_pool'] convert_widget_pool_params(widget_pool_params, obj) end end params end private def convert_widget_pool_params(widget_pool_params, obj) widget_pool_params.each_pair do |widget_id, widget_params| widget = obj.widget_from_pool(widget_id) if widget_params.present? convert_params(widget_params, widget) end end end def convert_params(params, obj) params.each do |key, value| type = obj.type_of_attribute(key.to_s) params[key] = case type when 'html' ContentConversion.convert_html_links(value, @host, @port) when 'linklist' ContentConversion.convert_linklist_urls(value, @host, @port) else value end end end end end