Class: Vedeu::Models::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/models/cell.rb

Overview

A Cell represents a single square of the terminal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Models::Cell

Returns a new instance of Vedeu::Models::Cell.

Options Hash (attributes):

  • colour (NilClass|String)
  • style (Object)
    NilClass|Array<Symbol|String>|Symbol|String
  • value (NilClass|String)
  • position (Vedeu::Geometry::Position)


31
32
33
34
35
# File 'lib/vedeu/models/cell.rb', line 31

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value || defaults.fetch(key))
  end
end

Instance Attribute Details

#colourNilClass|String (readonly)



11
12
13
# File 'lib/vedeu/models/cell.rb', line 11

def colour
  @colour
end

#styleNilClass|Array<Symbol|String>|Symbol|String (readonly)



15
16
17
# File 'lib/vedeu/models/cell.rb', line 15

def style
  @style
end

#valueNilClass|String (readonly)



19
20
21
# File 'lib/vedeu/models/cell.rb', line 19

def value
  @value
end

Instance Method Details

#defaultsHash<Symbol => void> (private)

Returns the default options/attributes for this class.



78
79
80
81
82
83
84
85
# File 'lib/vedeu/models/cell.rb', line 78

def defaults
  {
    colour:   nil,
    style:    nil,
    value:    '',
    position: [1, 1],
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

An object is equal when its values are the same.



41
42
43
44
# File 'lib/vedeu/models/cell.rb', line 41

def eql?(other)
  self.class == other.class && value == other.value &&
    position == other.position
end

#positionVedeu::Geometry::Position



48
49
50
# File 'lib/vedeu/models/cell.rb', line 48

def position
  Vedeu::Geometry::Position.coerce(@position)
end

#to_hashHash



53
54
55
56
57
58
59
60
# File 'lib/vedeu/models/cell.rb', line 53

def to_hash
  {
    colour:   colour.to_s,
    style:    style.to_s,
    value:    value.to_s,
    position: position.to_s,
  }
end

#to_html(_options = {}) ⇒ String



64
65
66
# File 'lib/vedeu/models/cell.rb', line 64

def to_html(_options = {})
  ''
end

#to_sString



69
70
71
# File 'lib/vedeu/models/cell.rb', line 69

def to_s
  value.to_s
end