class TrisulRP::Keys::Port

UDP/TCP port a 2 byte number

Public Class Methods

invert_xform(dstring) click to toggle source

human string to key handles formats

> Port-80

> port-80

> 80

# File lib/trisulrp/keys.rb, line 87
def self.invert_xform(dstring)
  if dstring.size > 5 and dstring[0..4].upcase == "PORT-"
    return "p-"+dstring.slice(5..-1).to_i.to_s(16).rjust(4,"0000").upcase
  else
    return "p-"+dstring.to_i.to_s(16).rjust(4,"0000").upcase
  end
end
is_human_form?(patt) click to toggle source

is_human_form?

# File lib/trisulrp/keys.rb, line 102
def self.is_human_form? patt
  patt[0..4].upcase == "PORT-" and ((1..65535).include? patt[5..-1].to_i)
end
is_key_form?(patt) click to toggle source

is_key_form?

# File lib/trisulrp/keys.rb, line 96
def self.is_key_form? patt
  return false if patt.nil?
  patt.length == 6 and patt[0] == 'p' and patt[1] == '-'
end
xform(kstring) { |s| ... } click to toggle source

key to human string

# File lib/trisulrp/keys.rb, line 76
def self.xform(kstring)
  s =  "Port-" + kstring[2..-1].hex.to_s
  yield s if block_given?
  return s
end