Sha256: efeb048ef673407940f8523e788875df8d780cf16b1995c7ec8cd7b4aca98032

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

module Vedeu

  module Renderers

    # Renders a {Vedeu::VirtualBuffer} or {Vedeu::Output} as JSON.
    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

14 entries across 14 versions & 1 rubygems

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