Module: Tickethub::Helpers
Constant Summary collapse
- DEFAULT_SEP =
Stolen from Rack:
/[&;] */n
Instance Method Summary collapse
- #camelize(value) ⇒ Object
- #escape(s) ⇒ Object
- #from_param(qs, d = nil) ⇒ Object
- #to_param(value, prefix = nil) ⇒ Object
- #to_path(*params) ⇒ Object
- #unescape(s, encoding = nil) ⇒ Object
Instance Method Details
#camelize(value) ⇒ Object
9 10 11 |
# File 'lib/tickethub/helpers.rb', line 9 def camelize(value) value.to_s.split('_').map {|w| w.capitalize }.join end |
#escape(s) ⇒ Object
53 54 55 |
# File 'lib/tickethub/helpers.rb', line 53 def escape(s) URI.encode_www_form_component(s) end |
#from_param(qs, d = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/tickethub/helpers.rb', line 33 def from_param(param) Rack::Utils.parse_nested_query(param) (value || '').split('&').each do |res| key, value = res.split('=') @params[key] = value end end |
#to_param(value, prefix = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tickethub/helpers.rb', line 17 def to_param(value, prefix = nil) case value when Array value.map { |v| to_param(v, "#{prefix}[]") }.join("&") when Hash value.map { |k, v| to_param(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k)) }.join("&") else raise ArgumentError, "value must be a Hash" if prefix.nil? "#{prefix}=#{escape(value)}" end end |
#to_path(*params) ⇒ Object
5 6 7 |
# File 'lib/tickethub/helpers.rb', line 5 def to_path(*params) params.map(&:to_s).reject(&:empty?) * '/' end |
#unescape(s, encoding = nil) ⇒ Object
58 59 60 |
# File 'lib/tickethub/helpers.rb', line 58 def unescape(s, encoding = Encoding::UTF_8) URI.decode_www_form_component(s, encoding) end |