Class: Hyde::Util::Query
- Inherits:
-
Object
- Object
- Hyde::Util::Query
- Defined in:
- lib/hyde/util/query.rb
Overview
Query string parser
Instance Method Summary collapse
-
#initialize(query) ⇒ Query
constructor
A new instance of Query.
-
#parse ⇒ Hash
Better(tm) query parser with Returns a hash with arrays Key semantics:.
-
#parse_shallow ⇒ Hash
Shallow query parser (does not do PHP-like array keys).
Constructor Details
#initialize(query) ⇒ Query
Returns a new instance of Query.
10 11 12 |
# File 'lib/hyde/util/query.rb', line 10 def initialize(query) @query = query end |
Instance Method Details
#parse ⇒ Hash
Better(tm) query parser with Returns a hash with arrays Key semantics:
-
‘key=value` creates a key value pair
-
‘key[]=value` appends `value` to an array named `key`
-
‘key=value` sets `value` at `index` of array named `key`
30 31 32 |
# File 'lib/hyde/util/query.rb', line 30 def parse construct_deep_hash(URI.decode_www_form(@query, Encoding::UTF_8)) end |
#parse_shallow ⇒ Hash
Shallow query parser (does not do PHP-like array keys)
16 17 18 19 20 |
# File 'lib/hyde/util/query.rb', line 16 def parse_shallow URI.decode_www_form(@query, Encoding::UTF_8) .sort_by { |array| array[0] } .to_h end |