Module: Imglab::Position

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#position(*args) ⇒ 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:

  • args (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(*args)
  case
  when args.size == 1 && valid_position?(args[0])
    args[0]
  when args.size == 2 && valid_position?(*args)
    args.join(",")
  else
    raise ArgumentError.new("Invalid position")
  end
end