Class: Hyde::Util::Query
- Inherits:
-
Object
- Object
- Hyde::Util::Query
- Includes:
- ParserCommon
- Defined in:
- lib/hyde/util/query.rb
Overview
TODO: encoding support???? Query string parser
Instance Method Summary collapse
-
#[](key) ⇒ String, Array
Get key from query.
-
#initialize(query) ⇒ Query
constructor
A new instance of Query.
-
#parse ⇒ Hash
Better(tm) query parser.
-
#parse_shallow ⇒ Hash
Shallow query parser (does not do PHP-like array keys).
Constructor Details
#initialize(query) ⇒ Query
Returns a new instance of Query.
13 14 15 |
# File 'lib/hyde/util/query.rb', line 13 def initialize(query) @query = query end |
Instance Method Details
#[](key) ⇒ String, Array
Get key from query.
40 41 42 |
# File 'lib/hyde/util/query.rb', line 40 def [](key) (@cache ||= parse)[key] end |
#parse ⇒ Hash
Better(tm) query parser. Returns a hash with arrays. Key semantics:
key=value
creates a key value pairkey[]=value
appendsvalue
to an array namedkey
key[index]=value
setsvalue
atindex
of array namedkey
33 34 35 |
# File 'lib/hyde/util/query.rb', line 33 def parse construct_deep_hash(URI.decode_www_form(@query)) end |
#parse_shallow ⇒ Hash
Shallow query parser (does not do PHP-like array keys)
19 20 21 22 23 |
# File 'lib/hyde/util/query.rb', line 19 def parse_shallow URI.decode_www_form(@query) .sort_by { |array| array[0] } .to_h end |