Class: TSparser::AribStringDecoder::Decoder::ControlCodeProcessor

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

Overview

Inner class to process control code(bytes).

Instance Method Summary collapse

Constructor Details

#initialize(control_code_map, decoded) ⇒ ControlCodeProcessor

Returns a new instance of ControlCodeProcessor.



296
297
298
299
# File 'lib/arib_string_decoder.rb', line 296

def initialize(control_code_map, decoded)
  @control_code_map = control_code_map
  @decoded = decoded
end

Instance Method Details

#exec(arg_num, proc) ⇒ Object



331
332
333
334
335
# File 'lib/arib_string_decoder.rb', line 331

def exec(arg_num, proc)
  args = []
  arg_num.times{ args << read_one }
  instance_exec(*args, &proc)
end

#get(byte) ⇒ Object



305
306
307
308
309
310
311
312
313
# File 'lib/arib_string_decoder.rb', line 305

def get(byte)
  if @control_code_map[:C0].match?(byte)
    return @control_code_map[:C0].get(byte)
  elsif @control_code_map[:C1].match?(byte)
    return @control_code_map[:C1].get(byte)
  else
    raise "Undefined code #{byte}."
  end
end

#match?(byte) ⇒ Boolean

Returns:

  • (Boolean)


301
302
303
# File 'lib/arib_string_decoder.rb', line 301

def match?(byte)
  return @control_code_map[:C0].match?(byte) || @control_code_map[:C1].match?(byte)
end

#nothingObject



337
338
# File 'lib/arib_string_decoder.rb', line 337

def nothing
end

#process(byte, binary) ⇒ Object



315
316
317
318
319
320
# File 'lib/arib_string_decoder.rb', line 315

def process(byte, binary)
  operation_name, args = get(byte)
  @binary = binary
  send(operation_name, *args)
  @binary = nil
end

#putstr(str) ⇒ Object



322
323
324
# File 'lib/arib_string_decoder.rb', line 322

def putstr(str)
  @decoded.push_str(str)
end

#read_oneObject



326
327
328
329
# File 'lib/arib_string_decoder.rb', line 326

def read_one
  raise "Binary is not found." unless @binary
  return @binary.read_byte_as_integer(1)
end