molten-trunk/molten5_withgrid/app/models/case_report.rb
def to_options(query)
      return query if query.is_a?(Hash)
      # some key parts stolen from CGI.parse
      query.
      split(/[&;]/n).inject({}) do |params, entry|
        key, value = entry.split('=',2).map{|s| CGI.unescape(s)}
        # treat arrays specially
        if key && key.from(-2).to(-1) == "[]"
          key = key.to(-3) # get rid of the "[]"
          params[key] ||= []
          params[key] << value
          params
        else
          params.merge(key => value)
        end
      end.
      # reject nil => nil entries that exist with &s at the end or beginning
      reject { |k, v| NON_QUERY_KEYS.include?(k) }
    end
# Takes a string like <tt>"foo=bar&baz=bing"</tt> and produces
# <tt>{"baz"=>"bing", "foo"=>"bar"}</tt>.
# 
# Operates on the <tt>query</tt> property to allow for merging options.
# 
# Examples
# 
#   case_report.query = "foo=bar&baz=bing"
#   case_report.to_options #=> {"baz"=>"bing", "foo"=>"bar"}
# 
# Returns the <tt>query</tt> string as a bonafide hash.
# 


Operates on the query property to allow for merging options.

Examples



Returns the query string as a bonafide hash.
Operates on the query property to allow for merging options . Examples Returns the query string as a bonafide hash .
def to_options(query)
      return query if query.is_a?(Hash)
      query.
      split(/[&;]/n).inject({}) do |params, entry|
        key, value = entry.split('=',2).map{|s| CGI.unescape(s)}
        if key && key.from(-2).to(-1) == "[]"
          key = key.to(-3) 
          params[key] ||= []
          params[key] << value
          params
        else
          params.merge(key => value)
        end
      end.
      reject { |k, v| NON_QUERY_KEYS.include?(k) }
    end
def to_options ( query ) return query if query . is_a? ( Hash ) query . split ( / [&;] /n ) . inject ( { } ) do | params , entry | key , value = entry . split ( '=' , 2 ) . map { | s | CGI . unescape ( s ) } if key && key . from ( - 2 ) . to ( - 1 ) == "[]" key = key . to ( - 3 ) params [ key ] ||= [ ] params [ key ] << value params else params . merge ( key => value ) end end . reject { | k , v | NON_QUERY_KEYS . include? ( k ) } end
Takes a string like <tt>"foo=bar&baz=bing"</tt> and produces
<tt>{"baz"=>"bing", "foo"=>"bar"}</tt>.
Takes a string like <tt > " foo = bar&baz = bing " < / tt > and produces <tt > { " baz " = > " bing " " foo " = > " bar " } < / tt > .
# some key parts stolen from CGI.parse # treat arrays specially # get rid of the "[]" # reject nil => nil entries that exist with &s at the end or beginning
query