app/controllers/mainpage_controller.rb
def create_resource(properties)
    resource = {}
    properties.each do |prop, value|
      ref = resource
      prop_array = prop.to_s.split(".")
      for p in 0..(prop_array.size - 1)
        is_array = false
        key = prop_array[p]
        # For properties that have array values, convert a name like
        # "snippet.tags[]" to snippet.tags, but set a flag to handle
        # the value as an array.
        if key[-2,2] == "[]"
          key = key[0...-2]
          is_array = true
        end
        if p == (prop_array.size - 1)
          if is_array
            if value == ""
              ref[key.to_sym] = []
            else
              ref[key.to_sym] = value.split(",")
            end
          elsif value != ""
            ref[key.to_sym] = value
          end
        elsif ref.include?(key.to_sym)
          ref = ref[key.to_sym]
        else
          ref[key.to_sym] = {}
          ref = ref[key.to_sym]
        end
      end
    end
    return resource
  end
# Build a resource based on a list of properties given as key-value pairs.
Build a resource based on a list of properties given as key-value pairs.
Build a resource based on a list of properties given as key - value pairs .
def create_resource(properties)
    resource = {}
    properties.each do |prop, value|
      ref = resource
      prop_array = prop.to_s.split(".")
      for p in 0..(prop_array.size - 1)
        is_array = false
        key = prop_array[p]
        if key[-2,2] == "[]"
          key = key[0...-2]
          is_array = true
        end
        if p == (prop_array.size - 1)
          if is_array
            if value == ""
              ref[key.to_sym] = []
            else
              ref[key.to_sym] = value.split(",")
            end
          elsif value != ""
            ref[key.to_sym] = value
          end
        elsif ref.include?(key.to_sym)
          ref = ref[key.to_sym]
        else
          ref[key.to_sym] = {}
          ref = ref[key.to_sym]
        end
      end
    end
    return resource
  end
def create_resource ( properties ) resource = { } properties . each do | prop , value | ref = resource prop_array = prop . to_s . split ( "." ) for p in 0 .. ( prop_array . size - 1 ) is_array = false key = prop_array [ p ] if key [ - 2 , 2 ] == "[]" key = key [ 0 ... - 2 ] is_array = true end if p == ( prop_array . size - 1 ) if is_array if value == "" ref [ key . to_sym ] = [ ] else ref [ key . to_sym ] = value . split ( "," ) end elsif value != "" ref [ key . to_sym ] = value end elsif ref . include? ( key . to_sym ) ref = ref [ key . to_sym ] else ref [ key . to_sym ] = { } ref = ref [ key . to_sym ] end end end return resource end
Build a resource based on a list of properties given as key-value pairs.
Build a resource based on a list of properties given as key - value pairs .
# For properties that have array values, convert a name like # "snippet.tags[]" to snippet.tags, but set a flag to handle # the value as an array.
properties