Sha256: 4b516199c0c8c1ded7cfdf4d2772ddd892c5318c35dfdc4485573b3c54033320

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

module Vedeu

  module Renderers

    # Renders a {Vedeu::VirtualBuffer} or {Vedeu::Output} as JSON.
    #
    # @api private
    class JSON

      # @param output [Array<Array<Vedeu::Char>>]
      # @return [String]
      def self.render(output)
        new(output).render
      end

      # @param output [Array<Array<Vedeu::Char>>]
      # @param path [String]
      # @return [String]
      # def self.to_file(output, path = nil)
      #   new(output).to_file(path)
      # end

      # Returns a new instance of Vedeu::Renderers::JSON.
      #
      # @param output [Array<Array<Vedeu::Char>>]
      # @return [Vedeu::Renderers::JSON]
      def initialize(output)
        @output = output
      end

      # @return [String]
      def render
        return '' if output.nil? || output.empty?

        out = ''
        Array(output).each do |line|
          out << ''
          line.each do |char|
            out << char.to_json
            out << "\n"
          end
          out << "\n"
        end
        out
      end

      protected

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

    end # JSON

  end # Renderers

end # Vedeu

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.4.39 lib/vedeu/output/renderers/json.rb
vedeu-0.4.38 lib/vedeu/output/renderers/json.rb
vedeu-0.4.37 lib/vedeu/output/renderers/json.rb
vedeu-0.4.36 lib/vedeu/output/renderers/json.rb
vedeu-0.4.35 lib/vedeu/output/renderers/json.rb
vedeu-0.4.34 lib/vedeu/output/renderers/json.rb
vedeu-0.4.33 lib/vedeu/output/renderers/json.rb