Class: BitmapCmdEditor::Validators::CreateImageValidator

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

Overview

To validate a new bitmap image table created

Author:

  • Diego Hernán Piccinini Lagos

Class Method Summary collapse

Class Method Details

.validate(args) ⇒ Object

Parameters:

  • args (Array)

    the command 0=> ‘I’ and 1=> columns 2 =>rows



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

def validate(args)
	begin
		raise CreateImageArgumentError.new(
			ErrorMessage.new(:command_wrong_arguments, {:arguments => 2}).show_content) unless args.count == 3
		begin
			columns= Integer(args[1])
			rows= Integer(args[2])
		rescue => err
			raise TypeError.new(ErrorMessage.new(:coordinates_are_not_integer).show_content)
		end
		ValidatorHelper.more_than_max('columns',BitmapCmdEditor::MAX_COLUMNS,columns)

		ValidatorHelper.more_than_max('rows',BitmapCmdEditor::MAX_ROWS,rows)

		ValidatorHelper.less_than_min('columns',BitmapCmdEditor::MIN_COLUMNS,columns)

		ValidatorHelper.less_than_min('rows',BitmapCmdEditor::MIN_ROWS,rows)

		:valid
	rescue  => err
		err.message
	end
end