Class: BitmapCmdEditor::Validators::VerticalLineValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmap_cmd_editor/validators/vertical_line_validator.rb

Overview

Author:

  • Diego Hernán Piccinini Lagos

Class Method Summary collapse

Class Method Details

.validate(args, bitmap_columns, bitmap_rows) ⇒ Object

Parameters:

  • args (Array)

    the command 0=> ‘V’ and 1=> column 2 => row start 3 => row end 4 => colour

  • bitmap_columns (Integer)

    number of columns of the image created

  • bitmap_rows (Integer)

    number of rows of the image created



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bitmap_cmd_editor/validators/vertical_line_validator.rb', line 9

def validate(args, bitmap_columns, bitmap_rows)
	begin
		raise VerticalLineArgumentError.new(
			ErrorMessage.new(:command_wrong_arguments, {:arguments => 4}).show_content) unless args.count == 5

		begin
			column= Integer(args[1])
			row_start= Integer(args[2])
			row_end= Integer(args[3])
		rescue => err
			raise TypeError.new(ErrorMessage.new(:coordinates_are_not_integer).show_content)
		end

		ValidatorHelper.out_of_range('columns',BitmapCmdEditor::MIN_COLUMNS,bitmap_columns,column)

		ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,row_start)

		ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,row_end)

		raise TypeError.new(ErrorMessage.new(:the_colour_is_invalid).show_content) unless ('A'..'Z').include?args[4]

		:valid
	rescue  => err
		err.message
	end
end