class Flyyer::FlyyerHash
A compatible qs stringify/parse (github.com/ljharb/qs)
Public Class Methods
new(hash)
click to toggle source
# File lib/flyyer.rb, line 181 def initialize(hash) @hash = hash end
Public Instance Methods
to_query(key = nil)
click to toggle source
# File lib/flyyer.rb, line 200 def to_query(key = nil) URI.encode_www_form(self.to_query_hash(key)) end
to_query_hash(key)
click to toggle source
# File lib/flyyer.rb, line 185 def to_query_hash(key) @hash.reduce({}) do |h, (k, v)| new_key = key.nil? ? k : "#{key}[#{k}]" v = Hash[v.each_with_index.to_a.map(&:reverse)] if v.is_a?(Array) if v.is_a?(Hash) h.merge!(FlyyerHash.new(v).to_query_hash(new_key)) elsif v.nil? # skip null values else h[new_key] = v end h end end