Sha256: 538fbffa01cc31f6d6226affd6597232c3f708fd09674b73fac8cae6de3d89d9

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

module Vedeu

  # Represents an invisible escape character sequence.
  #
  class Escape

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

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

      @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
    end

    # @return [String]
    def colour
      ''
    end

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

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

    # @return [String]
    def style
      ''
    end

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

    private

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

  end # Escape

end # Vedeu

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.5.13 lib/vedeu/models/escape.rb
vedeu-0.5.12 lib/vedeu/models/escape.rb
vedeu-0.5.11 lib/vedeu/models/escape.rb
vedeu-0.5.10 lib/vedeu/models/escape.rb
vedeu-0.5.9 lib/vedeu/models/escape.rb
vedeu-0.5.8 lib/vedeu/models/escape.rb
vedeu-0.5.7 lib/vedeu/models/escape.rb
vedeu-0.5.6 lib/vedeu/models/escape.rb