Sha256: 5d59c113b2d8c5381748508a382c8c3b127f5c5ec1e3ef1ac8e6b6450c2d941f

Contents?: true

Size: 630 Bytes

Versions: 7

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

module SimpleTextExtract
  class TempfileExtractor < TextExtractor
    attr_reader :filename, :raw

    def initialize(filename:, raw:)
      @filename = filename
      @raw = String.new(raw, encoding: Encoding::UTF_8)

      write_raw
    end

    private

      def file
        @file ||= Tempfile.new(filepath)
      end

      def write_raw
        file.write(raw)
        file.rewind
      end

      def cleanup
        file.close
        file.unlink
      end

      def filepath
        @filepath ||= filename.split(".").yield_self { |parts| [parts[0], ".#{parts[1]}"] }
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple_text_extract-0.3.0 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.2.1 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.2.0 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.1.3 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.1.2 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.1.1 lib/simple_text_extract/tempfile_extractor.rb
simple_text_extract-0.1.0 lib/simple_text_extract/tempfile_extractor.rb