Sha256: fad57cbab36ef0f6d909a4df4d2102187c91cfe0e3bc837a2eaa8f952109fcec

Contents?: true

Size: 1.96 KB

Versions: 10

Compression:

Stored size: 1.96 KB

Contents

module Vedeu

  module Models

    # Represents an invisible escape character sequence.
    #
    # @api private
    #
    class Escape

      # @!attribute [r] value
      # @return [String]
      attr_reader :value

      # Returns a new instance of Vedeu::Models::Escape.
      #
      # @param attributes [String]
      # @option attributes position
      #   [Vedeu::Geometries::Position|Array<Fixnum>]
      # @option attributes value [String]
      # @return [Vedeu::Models::Escape]
      def initialize(attributes = {})
        defaults.merge!(attributes).each do |key, value|
          instance_variable_set("@#{key}", value)
        end
      end

      # @return [Boolean]
      def cell?
        false
      end

      # @return [NilClass]
      def null
        nil
      end
      alias_method :background, :null
      alias_method :colour,     :null
      alias_method :foreground, :null
      alias_method :style,      :null

      # An object is equal when its values are the same.
      #
      # @param other [Vedeu::Models::Escape]
      # @return [Boolean]
      def eql?(other)
        self.class == other.class && value == other.value
      end
      alias_method :==, :eql?

      # @return [String]
      def position
        Vedeu::Geometries::Position.coerce(@position)
      end

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

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

      # @return [String]
      def to_s
        "#{position}#{value}".freeze
      end
      alias_method :to_str, :to_s

      private

      # @return [Hash]
      def defaults
        {
          position: [1, 1],
          value:    '',
        }
      end

    end # Escape

  end # Models

end # Vedeu

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vedeu-0.6.70 lib/vedeu/models/escape.rb
vedeu-0.6.69 lib/vedeu/models/escape.rb
vedeu-0.6.68 lib/vedeu/models/escape.rb
vedeu-0.6.67 lib/vedeu/models/escape.rb
vedeu-0.6.66 lib/vedeu/models/escape.rb
vedeu-0.6.65 lib/vedeu/models/escape.rb
vedeu-0.6.64 lib/vedeu/models/escape.rb
vedeu-0.6.63 lib/vedeu/models/escape.rb
vedeu-0.6.62 lib/vedeu/models/escape.rb
vedeu-0.6.61 lib/vedeu/models/escape.rb