Sha256: 9facfa0844b8a514c7b3941fed19eeeece661694421dd408beb8014b6daeb80e

Contents?: true

Size: 798 Bytes

Versions: 9

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Renderers

    # Renders a {Vedeu::Buffers::Terminal} as JSON.
    #
    # @api private
    #
    class JSON < Vedeu::Renderers::File

      include Vedeu::Renderers::Options

      # Render a cleared output.
      #
      # @return [Hash]
      def clear
        render({})
      end

      private

      # @return [Array]
      def as_hash
        output.content.map(&:to_h)
      end

      # @return [String]
      def content
        if hash?(output)
          ::JSON.pretty_generate(output)

        else
          Vedeu.log(type:    :render,
                    message: "#{self.class.name}#content: #{output.class.name}")

          ::JSON.pretty_generate(as_hash)
        end
      end

    end # JSON

  end # Renderers

end # Vedeu

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/renderers/json.rb
vedeu-0.8.31 lib/vedeu/renderers/json.rb
vedeu-0.8.30 lib/vedeu/renderers/json.rb
vedeu-0.8.29 lib/vedeu/renderers/json.rb
vedeu-0.8.28 lib/vedeu/renderers/json.rb
vedeu-0.8.27 lib/vedeu/renderers/json.rb
vedeu-0.8.26 lib/vedeu/renderers/json.rb
vedeu-0.8.25 lib/vedeu/renderers/json.rb
vedeu-0.8.24 lib/vedeu/renderers/json.rb