Class: TSparser::AribStringDecoder::Decoder::Decoded

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

Overview

Inner class to retain decoded string.

Instance Method Summary collapse

Constructor Details

#initializeDecoded

Returns a new instance of Decoded.



384
385
386
387
# File 'lib/arib_string_decoder.rb', line 384

def initialize
  @decoded_utf_8 = "".encode(Encoding::UTF_8)
  @buffer        = Binary.new
end

Instance Method Details

#code_type_change(type) ⇒ Object



415
416
417
418
419
# File 'lib/arib_string_decoder.rb', line 415

def code_type_change(type)
  return false if @buffer_current_code_type == type
  @buffer_current_code_type = type
  return true
end

#convert_bufferObject



421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/arib_string_decoder.rb', line 421

def convert_buffer
  unless @buffer.empty?
    @decoded_utf_8 << @buffer.encode(Encoding::UTF_8, Encoding::ISO_2022_JP)
    @buffer.clear
    @buffer_current_code_type = nil
  end
rescue => error
  STDERR.puts "Convert error."
  STDERR.puts "Now buffer(binary): #{@bugger.dump}"
  STDERR.puts "Now decoded(utf-8): #{decoded_utf_8}"
  raise error
end

#push_jis_ascii(byte) ⇒ Object



394
395
396
397
398
399
# File 'lib/arib_string_decoder.rb', line 394

def push_jis_ascii(byte)
  if code_type_change(CODE_ASCII)
    @buffer << Binary.from_int(ESC, 0x28, 0x42)
  end
  @buffer << byte
end

#push_jis_hankaku(byte) ⇒ Object



401
402
403
404
405
406
# File 'lib/arib_string_decoder.rb', line 401

def push_jis_hankaku(byte)
  if code_type_change(CODE_HANKAKU)
    @buffer << Binary.from_int(ESC, 0x28, 0x49)
  end
  @buffer << byte
end

#push_jis_zenkaku(byte1, byte2) ⇒ Object



408
409
410
411
412
413
# File 'lib/arib_string_decoder.rb', line 408

def push_jis_zenkaku(byte1, byte2)
  if code_type_change(CODE_ZENKAKU)
    @buffer << Binary.from_int(ESC, 0x24, 0x42)
  end
  @buffer << byte1 << byte2
end

#push_str(string) ⇒ Object



389
390
391
392
# File 'lib/arib_string_decoder.rb', line 389

def push_str(string)
  convert_buffer
  @decoded_utf_8 << string
end

#to_sObject



434
435
436
437
# File 'lib/arib_string_decoder.rb', line 434

def to_s
  convert_buffer
  return @decoded_utf_8
end