Class: Vedeu::Models::Cell
- Inherits:
-
Object
- Object
- Vedeu::Models::Cell
- Defined in:
- lib/vedeu/models/cell.rb
Overview
A Cell represents a single square of the terminal.
Instance Attribute Summary collapse
- #colour ⇒ NilClass|String readonly
- #style ⇒ NilClass|Array<Symbol|String>|Symbol|String readonly
- #value ⇒ NilClass|String readonly
Instance Method Summary collapse
- #cell? ⇒ Boolean
-
#defaults ⇒ Hash<Symbol => void>
private
Returns the default options/attributes for this class.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(attributes = {}) ⇒ Vedeu::Models::Cell
constructor
Returns a new instance of Vedeu::Models::Cell.
- #position ⇒ Vedeu::Geometry::Position
- #to_hash ⇒ Hash
- #to_html(_options = {}) ⇒ String
- #to_s ⇒ String
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Models::Cell
Returns a new instance of Vedeu::Models::Cell.
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
#colour ⇒ NilClass|String (readonly)
11 12 13 |
# File 'lib/vedeu/models/cell.rb', line 11 def colour @colour end |
#style ⇒ NilClass|Array<Symbol|String>|Symbol|String (readonly)
15 16 17 |
# File 'lib/vedeu/models/cell.rb', line 15 def style @style end |
#value ⇒ NilClass|String (readonly)
19 20 21 |
# File 'lib/vedeu/models/cell.rb', line 19 def value @value end |
Instance Method Details
#cell? ⇒ Boolean
38 39 40 |
# File 'lib/vedeu/models/cell.rb', line 38 def cell? true end |
#defaults ⇒ Hash<Symbol => void> (private)
Returns the default options/attributes for this class.
83 84 85 86 87 88 89 90 |
# File 'lib/vedeu/models/cell.rb', line 83 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.
46 47 48 49 |
# File 'lib/vedeu/models/cell.rb', line 46 def eql?(other) self.class == other.class && value == other.value && position == other.position end |
#position ⇒ Vedeu::Geometry::Position
53 54 55 |
# File 'lib/vedeu/models/cell.rb', line 53 def position Vedeu::Geometry::Position.coerce(@position) end |
#to_hash ⇒ Hash
58 59 60 61 62 63 64 65 |
# File 'lib/vedeu/models/cell.rb', line 58 def to_hash { colour: colour.to_s, style: style.to_s, value: value.to_s, position: position.to_s, } end |
#to_html(_options = {}) ⇒ String
69 70 71 |
# File 'lib/vedeu/models/cell.rb', line 69 def to_html( = {}) '' end |
#to_s ⇒ String
74 75 76 |
# File 'lib/vedeu/models/cell.rb', line 74 def to_s value.to_s end |