Class: Exerb::String

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/string.rb

Overview

#

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value) ⇒ String

Returns a new instance of String.



15
16
17
18
# File 'lib/exerb/string.rb', line 15

def initialize (name, value)
  @name = name
  @value = value
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/exerb/string.rb', line 20

def name
  @name
end

#valueObject

Returns the value of attribute value.



20
21
22
# File 'lib/exerb/string.rb', line 20

def value
  @value
end

Instance Method Details

#packObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/exerb/string.rb', line 22

def pack
  # next two lines work for Ascii
  # fmtstr = "SA#{@value.length}SSSSSSSSSSSSSSS"
  # return [@value.length,@value,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].pack(fmtstr)
  # We want UTF-16 - who knew?
  intchrs = []
  intchrs[0] = @value.length
  @value.each_byte {|c| intchrs << c.to_i}
  15.times {|i| intchrs << 0}
  return intchrs.pack("S#{intchrs.length}")
end