Sha256: a354961ba91b959c27aaebc3ec7f910545c7863e8f204e83932cb96a69966b66

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

module Vedeu

  module Renderers

    # Converts a grid of {Vedeu::Char} objects into a stream of escape sequences
    # and content suitable for a terminal, and writes them to a file in the /tmp
    # directory.
    class File

      # @param output [Array<Array<Vedeu::Char>>]
      # @param options [Hash]
      # @return [String]
      def self.render(output, options = {})
        new(output, options).render
      end

      # Returns a new instance of Vedeu::Renderers::File.
      #
      # @param output [Array<Array<Vedeu::Char>>]
      # @param options [Hash]
      # @return [Vedeu::Renderers::File]
      def initialize(output, options = {})
        @output  = output
        @options = options
      end

      # @return [String]
      def render
        ::File.open(path, 'w') { |f| f.write(parsed) }

        parsed
      end

      protected

      # @!attribute [r] output
      # @return [Array<Array<Vedeu::Char>>]
      attr_reader :output

      private

      # @return [String]
      def path
        "/tmp/#{filename}"
      end

      # @return [String]
      def filename
        if timestamp?
          "out_#{timestamp}"

        else
          'out'

        end
      end

      # @return [String]
      def parsed
        @parsed ||= Vedeu::Compressor.new(output).render
      end

      # @return [Float]
      def timestamp
        @timestamp ||= Time.now.to_f
      end

      # @return [Boolean]
      def timestamp?
        return true if options[:timestamp]

        false
      end

      # @return [Hash]
      def options
        defaults.merge!(@options)
      end

      # @return [Hash]
      def defaults
        {
          timestamp: false,
        }
      end

    end # File

  end # Renderers

end # Vedeu

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.4.29 lib/vedeu/output/renderers/file.rb
vedeu-0.4.28 lib/vedeu/output/renderers/file.rb
vedeu-0.4.27 lib/vedeu/output/renderers/file.rb
vedeu-0.4.26 lib/vedeu/output/renderers/file.rb
vedeu-0.4.25 lib/vedeu/output/renderers/file.rb
vedeu-0.4.24 lib/vedeu/output/renderers/file.rb
vedeu-0.4.23 lib/vedeu/output/renderers/file.rb
vedeu-0.4.22 lib/vedeu/output/renderers/file.rb
vedeu-0.4.21 lib/vedeu/output/renderers/file.rb
vedeu-0.4.20 lib/vedeu/output/renderers/file.rb
vedeu-0.4.19 lib/vedeu/output/renderers/file.rb