Sha256: e0cb389a44f94625c968f5c31246d002f9d395097b040918baef6d88ae5c4813

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 KB

Contents

module Vedeu

  module Models

    # Represents an invisible escape character sequence.
    #
    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::Geometry::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::Geometry::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

25 entries across 25 versions & 1 rubygems

Version Path
vedeu-0.6.50 lib/vedeu/models/escape.rb
vedeu-0.6.49 lib/vedeu/models/escape.rb
vedeu-0.6.48 lib/vedeu/models/escape.rb
vedeu-0.6.47 lib/vedeu/models/escape.rb
vedeu-0.6.46 lib/vedeu/models/escape.rb
vedeu-0.6.45 lib/vedeu/models/escape.rb
vedeu-0.6.44 lib/vedeu/models/escape.rb
vedeu-0.6.43 lib/vedeu/models/escape.rb
vedeu-0.6.42 lib/vedeu/models/escape.rb
vedeu-0.6.41 lib/vedeu/models/escape.rb
vedeu-0.6.40 lib/vedeu/models/escape.rb
vedeu-0.6.39 lib/vedeu/models/escape.rb
vedeu-0.6.38 lib/vedeu/models/escape.rb
vedeu-0.6.37 lib/vedeu/models/escape.rb
vedeu-0.6.36 lib/vedeu/models/escape.rb
vedeu-0.6.35 lib/vedeu/models/escape.rb
vedeu-0.6.34 lib/vedeu/models/escape.rb
vedeu-0.6.33 lib/vedeu/models/escape.rb
vedeu-0.6.32 lib/vedeu/models/escape.rb
vedeu-0.6.31 lib/vedeu/models/escape.rb