Class: Rho::RhoSupport::UrlEncodedPairParser
- Defined in:
- lib/rho/rhosupport.rb
Overview
:nodoc:
Constant Summary collapse
- KEY_REGEXP =
%r{([^\[\]=&]+)}
- BRACKETED_KEY_REGEXP =
%r{\[([^\[\]=&]+)\]}
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
-
#initialize(pairs = []) ⇒ UrlEncodedPairParser
constructor
A new instance of UrlEncodedPairParser.
-
#parse(key, value) ⇒ Object
Parse the query string.
Constructor Details
#initialize(pairs = []) ⇒ UrlEncodedPairParser
Returns a new instance of UrlEncodedPairParser.
55 56 57 58 59 |
# File 'lib/rho/rhosupport.rb', line 55 def initialize(pairs = []) super('') @result = {} pairs.each { |key, value| parse(key, value) } end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
53 54 55 |
# File 'lib/rho/rhosupport.rb', line 53 def parent @parent end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
53 54 55 |
# File 'lib/rho/rhosupport.rb', line 53 def result @result end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
53 54 55 |
# File 'lib/rho/rhosupport.rb', line 53 def top @top end |
Instance Method Details
#parse(key, value) ⇒ Object
Parse the query string
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rho/rhosupport.rb', line 65 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 |