Class: TrisulRP::Keys::HNumber

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

Class Method Summary collapse

Class Method Details

.invert_xform(width, dstring) {|ret| ... } ⇒ Object

human string to key

> width padding eg to output 000B when input = 11 and field is a 2 byte

> dstring input decimal

Yields:

  • (ret)


26
27
28
29
30
# File 'lib/trisulrp/keys.rb', line 26

def self.invert_xform(width,dstring)
  ret = dstring.to_i.to_s(16).rjust(width,"0").upcase
  yield ret if block_given?
  ret
end

.is_human_form?(patt) ⇒ Boolean

is_human_pattern?

Returns:

  • (Boolean)


39
40
41
# File 'lib/trisulrp/keys.rb', line 39

def self.is_human_form? patt
  patt.to_i > 0 or patt.squeeze("0") == "0"
end

.is_key_form?(patt) ⇒ Boolean

is_key_pattern?

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/trisulrp/keys.rb', line 33

def self.is_key_form? patt
  return false if patt.nil?
  [2,4,8].member? patt.length and patt =~ /(\d|[a-f]|[A-F])+/
end

.xform(kstring) {|ret| ... } ⇒ Object

key to human string

> width unused

> kstring = hex number like A011

output is a decimal number

Yields:

  • (ret)


17
18
19
20
21
# File 'lib/trisulrp/keys.rb', line 17

def self.xform(kstring)
  ret = kstring.hex.to_s
  yield ret if block_given?
  ret
end