Class: BitmapCmdEditor::Bitmap

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

Overview

It’s the main object is instantiated empty when the application start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBitmap

Returns a new instance of Bitmap.



9
10
11
12
13
# File 'lib/bitmap_cmd_editor/bitmap.rb', line 9

def initialize
	@table=[]
	@columns = 0
	@rows = 0
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/bitmap_cmd_editor/bitmap.rb', line 6

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/bitmap_cmd_editor/bitmap.rb', line 6

def rows
  @rows
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/bitmap_cmd_editor/bitmap.rb', line 6

def table
  @table
end

Instance Method Details

#process_command(input) ⇒ Object

process the operations commands availables view the constant COMMANDS, X is excluded because it is a system command not a bitmap command

Parameters:

  • input (String)

    the command typed for example: I 5 6

Returns:

  • CommandValidator.validate response [Symbol|String] could be :valid or Error Message string



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bitmap_cmd_editor/bitmap.rb', line 19

def process_command(input)

	validator=Validators::CommandValidator.validate(input)
	if validator == :valid
		args = input.split(' ')
		case args[0]
		when 'I'
			create_image(args)
		when 'C'
			clear_image(args)
		when 'L'
			colours_pixel(args)
		when 'V'
			draw_vertical_line(args)
		when 'H'
			draw_horizontal_line(args)
		when 'F'
			fill_region(args)
		when 'S'
			print_table(args)
		end
	else
		validator
	end
end