Module: Watobo::Mixin::Transcoders
- Defined in:
- lib/watobo/mixins/transcoders.rb
Instance Method Summary collapse
- #b64decode ⇒ Object
- #b64encode ⇒ Object
- #hex2int ⇒ Object
- #hexdecode ⇒ Object
- #hexencode ⇒ Object
- #url_decode ⇒ Object
- #url_encode ⇒ Object
Instance Method Details
#b64decode ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/watobo/mixins/transcoders.rb', line 22 def b64decode err_count = 0 b64string = self begin rs = Base64.strict_decode64(b64string) #rs = Base64.decode64(b64string) return rs rescue b64string.gsub!(/.$/,'') err_count += 1 retry if err_count < 4 return "" end end |
#b64encode ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/watobo/mixins/transcoders.rb', line 37 def b64encode begin plain = self #rs = Base64.strict_encode64(plain) rs = Base64.strict_encode64(plain) # we only need a simple string without linebreaks #rs.gsub!(/\n/,'') #rs.strip! return rs rescue return "" end end |
#hex2int ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/watobo/mixins/transcoders.rb', line 51 def hex2int begin plain = self.strip if plain =~ /^[0-9a-fA-F]{1,8}$/ then return plain.hex else return "" end rescue return "" end end |
#hexdecode ⇒ Object
74 75 76 77 |
# File 'lib/watobo/mixins/transcoders.rb', line 74 def hexdecode [ self ].pack("H*") end |
#hexencode ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/watobo/mixins/transcoders.rb', line 64 def hexencode begin self.unpack("H*")[0] rescue return "" end end |
#url_decode ⇒ Object
18 19 20 |
# File 'lib/watobo/mixins/transcoders.rb', line 18 def url_decode CGI::unescape(self) end |
#url_encode ⇒ Object
14 15 16 |
# File 'lib/watobo/mixins/transcoders.rb', line 14 def url_encode CGI::escape(self) end |