module Net::TNS::StringHelpers

This module includes common string helper methods for monkey-patching or mixing-in to string objects.

Constants

HEXCHARS

Public Instance Methods

tns_hexify() click to toggle source

Adapted from the Ruby Black Bag (github.com/emonti/rbkb/) Convert a string to ASCII hex string

# File lib/net/tns/helpers/string_helpers.rb, line 9
def tns_hexify
  self.each_byte.map do |byte|
    (HEXCHARS[(byte >> 4)] + HEXCHARS[(byte & 0xf )])
  end.join()
end
tns_unhexify(d=/\s*/) click to toggle source

Convert ASCII hex string to raw.

Parameters:

d = optional 'delimiter' between hex bytes (zero+ spaces by default)
# File lib/net/tns/helpers/string_helpers.rb, line 20
def tns_unhexify(d=/\s*/)
  self.strip.gsub(/([A-Fa-f0-9]{1,2})#{d}?/) { $1.hex.chr }
end