Module: Spectate::Encode
- Included in:
- Status
- Defined in:
- lib/spectate/encode.rb
Overview
A convenience module to provide URI-safe versions of spectator names. It essentially just uses URI::Escape on the strings, but with the additional conversion of spaces to underscores (and underscores to double underscores) because having lots of ‘%20’ blobs in a URL is painful on the eyes.
Instance Method Summary collapse
-
#decode(name) ⇒ Object
Turns a URI-safe name generated by ‘encode’ back into a reasonable string.
-
#encode(name) ⇒ Object
Makes a name URI-safe, with the minor cosmetic tweak of underscoring spaces.
Instance Method Details
#decode(name) ⇒ Object
Turns a URI-safe name generated by ‘encode’ back into a reasonable string.
17 18 19 20 21 |
# File 'lib/spectate/encode.rb', line 17 def decode(name) name.gsub!(/_(?!_)/,' ') name.gsub!(/_ /,'_') CGI::unescape(name) end |
#encode(name) ⇒ Object
Makes a name URI-safe, with the minor cosmetic tweak of underscoring spaces.
10 11 12 13 14 |
# File 'lib/spectate/encode.rb', line 10 def encode(name) name.gsub!(/_/,'__') name.tr!(' ','_') CGI::escape(name) end |