Class: CGIMethods::FormEncodedPairParser

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/action_controller/cgi_ext/cgi_methods.rb

Overview

:nodoc:

Constant Summary collapse

KEY_REGEXP =
%r{([^\[\]=&]+)}
BRACKETED_KEY_REGEXP =
%r{\[([^\[\]=&]+)\]}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pairs = []) ⇒ FormEncodedPairParser

Returns a new instance of FormEncodedPairParser.



118
119
120
121
122
# File 'lib/action_controller/cgi_ext/cgi_methods.rb', line 118

def initialize(pairs = [])
  super('')
  @result = {}
  pairs.each { |key, value| parse(key, value) }
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



116
117
118
# File 'lib/action_controller/cgi_ext/cgi_methods.rb', line 116

def parent
  @parent
end

#resultObject (readonly)

Returns the value of attribute result.



116
117
118
# File 'lib/action_controller/cgi_ext/cgi_methods.rb', line 116

def result
  @result
end

#topObject (readonly)

Returns the value of attribute top.



116
117
118
# File 'lib/action_controller/cgi_ext/cgi_methods.rb', line 116

def top
  @top
end

Instance Method Details

#parse(key, value) ⇒ Object

Parse the query string



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/action_controller/cgi_ext/cgi_methods.rb', line 128

def parse(key, value)
  self.string = key
  @top, @parent = result, nil
  
  # First scan the bare key
  key = scan(KEY_REGEXP) or return
  key = post_key_check(key)
        
  # Then scan as many nestings as present
  until eos? 
    r = scan(BRACKETED_KEY_REGEXP) or return
    key = self[1]
    key = post_key_check(key)
  end
 
  bind(key, value)
end