Sha256: ae677692a9d712372ca04f4e497a9db285e7682faa5e836eb7870dbd59536f3a

Contents?: true

Size: 773 Bytes

Versions: 5

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Renderers

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

      include Vedeu::Renderers::Options

      # Render a cleared output.
      #
      # @return [void]
      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

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.8.7 lib/vedeu/renderers/json.rb
vedeu-0.8.6 lib/vedeu/renderers/json.rb
vedeu-0.8.5 lib/vedeu/renderers/json.rb
vedeu-0.8.4 lib/vedeu/renderers/json.rb
vedeu-0.8.3 lib/vedeu/renderers/json.rb