Sha256: b49db807d88cf0bfc0fded3971a5f7c2e3e2a48213a1f3a8d3a26af82911cc80

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Cells

    # Provides the character/escape sequence to draw one cell of a
    # with a custom value, colour and style.
    #
    # The Vedeu::Cells::Escape object represents an escape sequence as
    # a single character, meaning they will behave dependent on the
    # context in which they are used.
    #
    # (In a terminal, an escape sequence makes sense, when a view is
    # being rendered as HTML, the sequence may be meaningless, for
    # example; the sequence to show or hide the cursor.)
    #
    # @api private
    #
    class Escape < Vedeu::Cells::Empty

      # @return [NilClass]
      def null
        nil
      end
      alias background null
      alias colour null
      alias foreground null
      alias style null

      # Return an empty hash as most escape sequences won't make
      # sense as JSON.
      #
      # @return [Hash<void>]
      def to_h
        {
          type:  type,
          value: value,
        }
      end
      alias to_hash to_h

      # Return an empty string as most escape sequences won't make
      # sense as HTML.
      #
      # @param _options [Hash] Ignored.
      # @return [String]
      def to_html(_options = {})
        ''
      end

      # @return [String]
      def to_s
        value
      end
      alias to_str to_s

      # @return [Symbol]
      def type
        :escape
      end

    end # Escape

  end # Cells

end # Vedeu

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.8.18 lib/vedeu/cells/escape.rb
vedeu-0.8.17 lib/vedeu/cells/escape.rb
vedeu-0.8.16 lib/vedeu/cells/escape.rb
vedeu-0.8.15 lib/vedeu/cells/escape.rb
vedeu-0.8.14 lib/vedeu/cells/escape.rb
vedeu-0.8.13 lib/vedeu/cells/escape.rb
vedeu-0.8.12 lib/vedeu/cells/escape.rb