Sha256: 1e8454b66a2296d8bc0a30f190b1e81b173462f13e6312e7baa39480114b9ee8

Contents?: true

Size: 547 Bytes

Versions: 1

Compression:

Stored size: 547 Bytes

Contents

module EncoderTools
  module Util
    class TextReader
      ENCODING_MARKER = "\xef\xbb\xbf".freeze

      def initialize(input)
        @input = input
      end

      def read
        strip_encoding_marker(
          @input.respond_to?(:read) ?  @input.read : @input)
      end

      def self.read(input)
        new(input).read
      end

      private
        def strip_encoding_marker(string)
          string[0, ENCODING_MARKER.size] == ENCODING_MARKER ?
            string[ENCODING_MARKER.size..-1] : string
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
encoder-tools-1.0.0 lib/encoder-tools/util/text_reader.rb