Module: URI
- Defined in:
- lib/swiftype/ext/backport-uri.rb
Overview
Stolen from ruby core’s uri/common.rb, with modifications to support 1.8.x
Class Method Summary collapse
Class Method Details
.encode_www_form(enum) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/swiftype/ext/backport-uri.rb', line 10 def self.encode_www_form(enum) enum.map do |k,v| if v.nil? encode_www_form_component(k) elsif v.respond_to?(:to_ary) v.to_ary.map do |w| str = encode_www_form_component(k) unless w.nil? str << '=' str << encode_www_form_component(w) end end.join('&') else str = encode_www_form_component(k) str << '=' str << encode_www_form_component(v) end end.join('&') end |
.encode_www_form_component(str) ⇒ Object
30 31 32 |
# File 'lib/swiftype/ext/backport-uri.rb', line 30 def self.encode_www_form_component(str) str.to_s.gsub(/[^*\-.0-9A-Z_a-z]/) { |chr| TBLENCWWWCOMP_[chr] } end |