Module: Crucigrama::Positionable

Included in:
Crossword, CrosswordBuilder
Defined in:
lib/crucigrama/positionable.rb

Overview

This module defines some methods of use to interact with Crosswords

Instance Method Summary collapse

Instance Method Details

#direction_other_than(direction) ⇒ Symbol?

Returns the direction opposite to the one given, that is, :horizontal for :vertical and :vertical for :horizontal; or nil if neither :horizontal nor :vertical is provided as direction.

Parameters:

  • direction (:horizontal, :vertical, nil)

    the direction whose opposite is queried

Returns:

  • (Symbol, nil)

    the direction opposite to the one given, that is, :horizontal for :vertical and :vertical for :horizontal; or nil if neither :horizontal nor :vertical is provided as direction



16
17
18
# File 'lib/crucigrama/positionable.rb', line 16

def direction_other_than(direction)
  { :horizontal => :vertical, :vertical => :horizontal}[direction]
end

#position(x, y) ⇒ Hash<Symbol,Integer>

Returns a hash with the horizontal and vertical coordinates.

Parameters:

  • x (Integer)

    the horizontal coordinate

  • y (Integer)

    the vertical coordinate

Returns:

  • (Hash<Symbol,Integer>)

    a hash with the horizontal and vertical coordinates



7
8
9
# File 'lib/crucigrama/positionable.rb', line 7

def position(x,y)
  {:horizontal => x, :vertical => y}
end