Class: Griddle::Point
- Inherits:
-
Struct
- Object
- Struct
- Griddle::Point
- Includes:
- Comparable
- Defined in:
- lib/griddle/point.rb
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#row ⇒ Object
Returns the value of attribute row.
Instance Method Summary collapse
-
#<=>(point) ⇒ Object
TODO: not sure this is really necessary, it seemed like a good idea at the time.
- #delta(point) ⇒ Object
- #move(directions) ⇒ Object
- #nil? ⇒ Boolean
-
#to_rectangle(point) ⇒ Object
‘point` is used to calculate the width and height of the new rectangle.
- #to_s ⇒ Object
- #zero? ⇒ Boolean
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col
4 5 6 |
# File 'lib/griddle/point.rb', line 4 def col @col end |
#row ⇒ Object
Returns the value of attribute row
4 5 6 |
# File 'lib/griddle/point.rb', line 4 def row @row end |
Instance Method Details
#<=>(point) ⇒ Object
TODO: not sure this is really necessary,
it seemed like a good idea at the time
9 10 11 |
# File 'lib/griddle/point.rb', line 9 def <=>(point) [row, col] <=> [point.row, point.col] end |
#delta(point) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/griddle/point.rb', line 25 def delta(point) Point.new( (self.row - point.row).abs, (self.col - point.col).abs ) end |
#move(directions) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/griddle/point.rb', line 45 def move(directions) directions.each_pair do |direction, amount| amount = amount.to_i case direction.to_sym when :up self.row -= amount when :down self.row += amount when :left self.col -= amount when :right self.col += amount end end end |
#nil? ⇒ Boolean
17 18 19 |
# File 'lib/griddle/point.rb', line 17 def nil? row.nil? && col.nil? end |
#to_rectangle(point) ⇒ Object
‘point` is used to calculate the width and height
of the new rectangle
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/griddle/point.rb', line 34 def to_rectangle(point) d = delta(point) Rectangle.new( row, col, d.col + 1, d.row + 1 ) end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/griddle/point.rb', line 13 def to_s "[#{row}, #{col}]" end |
#zero? ⇒ Boolean
21 22 23 |
# File 'lib/griddle/point.rb', line 21 def zero? row.zero? && col.zero? end |