Class: TSparser::AribStringDecoder::Decoder::Decoded
- Inherits:
-
Object
- Object
- TSparser::AribStringDecoder::Decoder::Decoded
- Defined in:
- lib/arib_string_decoder.rb
Overview
Inner class to retain decoded string.
Instance Method Summary collapse
- #code_type_change(type) ⇒ Object
- #convert_buffer ⇒ Object
-
#initialize ⇒ Decoded
constructor
A new instance of Decoded.
- #push_jis_ascii(byte) ⇒ Object
- #push_jis_hankaku(byte) ⇒ Object
- #push_jis_zenkaku(byte1, byte2) ⇒ Object
- #push_str(string) ⇒ Object
- #to_s ⇒ Object
Constructor Details
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_buffer ⇒ Object
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_s ⇒ Object
434 435 436 437 |
# File 'lib/arib_string_decoder.rb', line 434 def to_s convert_buffer return @decoded_utf_8 end |