Class: PrintSquare::Vector
- Inherits:
-
Object
- Object
- PrintSquare::Vector
- Defined in:
- lib/print_square/vector.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#position ⇒ Object
Returns the value of attribute position.
-
#size ⇒ Object
Returns the value of attribute size.
-
#turn ⇒ Object
Returns the value of attribute turn.
Instance Method Summary collapse
- #bounds? ⇒ Boolean
-
#initialize(direction, size, size_offset = 1) ⇒ Vector
constructor
A new instance of Vector.
- #next ⇒ Object
Constructor Details
#initialize(direction, size, size_offset = 1) ⇒ Vector
Returns a new instance of Vector.
5 6 7 8 9 |
# File 'lib/print_square/vector.rb', line 5 def initialize(direction, size, size_offset=1) @direction, @size, @size_offset = direction, size, size_offset @position = size.even? ? 0 : size - 1 @offset = 0 end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
3 4 5 |
# File 'lib/print_square/vector.rb', line 3 def direction @direction end |
#offset ⇒ Object
Returns the value of attribute offset.
3 4 5 |
# File 'lib/print_square/vector.rb', line 3 def offset @offset end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/print_square/vector.rb', line 3 def position @position end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/print_square/vector.rb', line 3 def size @size end |
#turn ⇒ Object
Returns the value of attribute turn.
3 4 5 |
# File 'lib/print_square/vector.rb', line 3 def turn @turn end |
Instance Method Details
#bounds? ⇒ Boolean
16 17 18 |
# File 'lib/print_square/vector.rb', line 16 def bounds? @position == (@direction == 1 ? (@size - @size_offset) : @offset) end |
#next ⇒ Object
11 12 13 14 |
# File 'lib/print_square/vector.rb', line 11 def next @position += @direction @turn.call if bounds? end |