Sha256: 183da819c5b7344fcc75a456b6bcc5ed070c9003c2808df1f886676c9cfe50dd

Contents?: true

Size: 1.74 KB

Versions: 18

Compression:

Stored size: 1.74 KB

Contents

module Vedeu

  # A Cell represents a single square of the terminal.
  #
  class Cell

    # @!attribute [r] colour
    # @return [NilClass|String]
    attr_reader :colour

    # @!attribute [r] style
    # @return [NilClass|Array<Symbol|String>|Symbol|String]
    attr_reader :style

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

    # @!attribute [r] x
    # @return [NilClass|Fixnum]
    attr_reader :x

    # @!attribute [r] y
    # @return [NilClass|Fixnum]
    attr_reader :y

    # Returns a new instance of Vedeu::Cell.
    #
    # @param attributes [Hash<Symbol => Array<Symbol|String>,
    #                                   Fixnum, String, Symbol]
    # @option attributes colour [NilClass|String]
    # @option attributes style [NilClass|Array<Symbol|String>|Symbol|String]
    # @option attributes value [NilClass|String]
    # @option attributes x [NilClass|Fixnum]
    # @option attributes y [NilClass|Fixnum]
    # @return [Vedeu::Cell]
    def initialize(attributes = {})
      @attributes = defaults.merge!(attributes)

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

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

    private

    # Returns the default options/attributes for this class.
    #
    # @return [Hash<Symbol => void>]
    def defaults
      {
        colour: nil,
        style:  nil,
        value:  nil,
        x:      nil,
        y:      nil,
      }
    end

  end # Cell

end # Vedeu

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
vedeu-0.5.8 lib/vedeu/models/cell.rb
vedeu-0.5.7 lib/vedeu/models/cell.rb
vedeu-0.5.6 lib/vedeu/models/cell.rb
vedeu-0.5.5 lib/vedeu/models/cell.rb
vedeu-0.5.4 lib/vedeu/models/cell.rb
vedeu-0.5.3 lib/vedeu/models/cell.rb
vedeu-0.5.2 lib/vedeu/models/cell.rb
vedeu-0.5.1 lib/vedeu/models/cell.rb
vedeu-0.5.0 lib/vedeu/models/cell.rb
vedeu-0.4.65 lib/vedeu/models/cell.rb
vedeu-0.4.64 lib/vedeu/models/cell.rb
vedeu-0.4.63 lib/vedeu/models/cell.rb
vedeu-0.4.62 lib/vedeu/models/cell.rb
vedeu-0.4.61 lib/vedeu/models/cell.rb
vedeu-0.4.60 lib/vedeu/models/cell.rb
vedeu-0.4.59 lib/vedeu/models/cell.rb
vedeu-0.4.58 lib/vedeu/models/cell.rb
vedeu-0.4.57 lib/vedeu/models/cell.rb