Class: TrisulRP::Keys::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/trisulrp/keys.rb

Overview

UDP/TCP port a 2 byte number

Class Method Summary collapse

Class Method Details

.invert_xform(dstring) ⇒ Object

human string to key handles formats

> Port-80

> port-80

> 80



87
88
89
90
91
92
93
# 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) ⇒ Boolean

is_human_form?

Returns:

  • (Boolean)


102
103
104
# 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) ⇒ Boolean

is_key_form?

Returns:

  • (Boolean)


96
97
98
99
# 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| ... } ⇒ Object

key to human string

Yields:

  • (s)


76
77
78
79
80
# 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