Class: BulkProcessor::StreamEncoder

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

Overview

Force encode a stream into UTF-8 by removing invalid and undefined characters.

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ StreamEncoder

Returns a new instance of StreamEncoder.



8
9
10
# File 'lib/bulk_processor/stream_encoder.rb', line 8

def initialize(stream)
  @stream = stream
end

Instance Method Details

#encodedString

Return the UTF-8 encoded string.

Note: this method reads the stream, so it will need to be rewound before attempting to read again.

Returns:

  • (String)

    a UTF-8 encoded string



18
19
20
# File 'lib/bulk_processor/stream_encoder.rb', line 18

def encoded
  stream.read.encode(Encoding::UTF_8, ENCODING_OPTIONS)
end