Class: Rho::RhoSupport::UrlEncodedPairParser

Inherits:
StringScanner show all
Defined in:
lib/framework/rho/rhosupport.rb

Overview

:nodoc:

Constant Summary collapse

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

Constants inherited from StringScanner

StringScanner::Id, StringScanner::Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StringScanner

#<<, #[], #beginning_of_line?, #bol?, #check, #check_until, #clear, #concat, #empty?, #eos?, #exist?, #get_byte, #getbyte, #getch, #inspect, #match?, #matched, #matched?, #matched_size, must_C_version, #peek, #peep, #pointer, #pointer=, #pos, #pos=, #post_match, #pre_match, #reset, #rest, #rest?, #rest_size, #restsize, #scan, #scan_full, #scan_until, #search_full, #skip, #skip_until, #string, #string=, #terminate, #unscan

Constructor Details

#initialize(pairs = []) ⇒ UrlEncodedPairParser

Returns a new instance of UrlEncodedPairParser.



139
140
141
142
143
# File 'lib/framework/rho/rhosupport.rb', line 139

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



137
138
139
# File 'lib/framework/rho/rhosupport.rb', line 137

def parent
  @parent
end

#resultObject (readonly)

Returns the value of attribute result.



137
138
139
# File 'lib/framework/rho/rhosupport.rb', line 137

def result
  @result
end

#topObject (readonly)

Returns the value of attribute top.



137
138
139
# File 'lib/framework/rho/rhosupport.rb', line 137

def top
  @top
end

Instance Method Details

#parse(key, value) ⇒ Object

Parse the query string



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/framework/rho/rhosupport.rb', line 149

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