Method: RubyLabs::BitLab#read_codes

Defined in:
lib/bitlab.rb

#read_codesObject

The data directory BitLabs has a file named “testcodes.txt” that contains a set of binary encodings of Hawaiian words. Call this method to read the encodings and return and an array of Message objects, one for each encoding. Users can try decoding the messages by hand before verifying their answer by passing them to decode. The messages are ordered from shortest to longest.

Example (assuming t is the Huffman tree for the full Hawaiian alphabet):

>> msgs = read_codes
=> [011010, ... 000101101100001100001011011000011011100110001011011100110001011010110011011010011110]
>> decode(msgs[-1], t)
=> "HUMUHUMUNUKUNUKUAPUA'A"


336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/bitlab.rb', line 336

def read_codes
  codes = Array.new
  fn = File.join(@@bitsDirectory, "testcodes.txt")
  File.open(fn).each do |line|
    line.chomp!
    code = Code.new(0,0)
    line.each_byte do |byte|
      code << byte[0]                # add least significant digit of ASCII "0" or "1"
    end
    msg = Message.new(:packed)
    msg << code
    codes << msg
  end
  return codes
end