Module: Imglab::Position

Extended by:
Position
Included in:
Position
Defined in:
lib/imglab/position.rb

Constant Summary collapse

HORIZONTAL =
%w[left center right].freeze
VERTICAL =
%w[top middle bottom].freeze

Instance Method Summary collapse

Instance Method Details

#position(*directions) ⇒ String

Returns a formatted position value as string.

Examples:

Specify a double direction position (horizontal, vertical order)

Imglab::Position.position("left", "bottom") #=> "left,bottom"

Specify a double direction position (vertical, horizontal order)

Imglab::Position.position("bottom", "left") #=> "bottom,left"

Specify a single direction position

Imglab::Position.position("left") #=> "left"

Specify an invalid double direction position (raising ArgumentError exception)

Imglab::Position.position("left", "center") #=> ArgumentError: Invalid position

Specify an invalid single direction position (raising ArgumentError exception)

Imglab::Position.position("lefts") #=> ArgumentError: Invalid position

Parameters:

  • directions (Array<String>, String)

    the position with two directions or one single direction as strings.

Returns:

  • (String)

    the formatted position with the specified arguments.

Raises:

  • (ArgumentError)

    when the specified arguments are not a valid position.



23
24
25
26
27
28
29
30
31
32
# File 'lib/imglab/position.rb', line 23

def position(*directions)
  case
  when directions.size == 1 && valid_position?(directions[0])
    directions[0]
  when directions.size == 2 && valid_position?(*directions)
    directions.join(",")
  else
    raise ArgumentError, "Invalid position"
  end
end