bitmap_cmd_editor 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +46 -0
  7. data/Rakefile +35 -0
  8. data/bin/bitmap_cmd_editor +10 -0
  9. data/bitmap_cmd_editor.gemspec +33 -0
  10. data/features/clear_table.feature +23 -0
  11. data/features/colours_pixel.feature +30 -0
  12. data/features/command_bitmap_cmd_editor.feature +48 -0
  13. data/features/create_bitmap.feature +29 -0
  14. data/features/draw_horinzontal_segment.feature +33 -0
  15. data/features/draw_vertical_segment.feature +33 -0
  16. data/features/fill_region.feature +44 -0
  17. data/features/show_content.feature +40 -0
  18. data/features/step_definitions/clear_table_step.rb +4 -0
  19. data/features/step_definitions/colours_pixel_step.rb +10 -0
  20. data/features/step_definitions/create_bitmap_step.rb +19 -0
  21. data/features/support/env.rb +2 -0
  22. data/lib/bitmap_cmd_editor.rb +3 -0
  23. data/lib/bitmap_cmd_editor/bitmap.rb +195 -0
  24. data/lib/bitmap_cmd_editor/client.rb +34 -0
  25. data/lib/bitmap_cmd_editor/exceptions.rb +17 -0
  26. data/lib/bitmap_cmd_editor/validators/clear_image_validator.rb +20 -0
  27. data/lib/bitmap_cmd_editor/validators/colour_pixel_validator.rb +34 -0
  28. data/lib/bitmap_cmd_editor/validators/command_validator.rb +21 -0
  29. data/lib/bitmap_cmd_editor/validators/create_image_validator.rb +34 -0
  30. data/lib/bitmap_cmd_editor/validators/error_message.rb +38 -0
  31. data/lib/bitmap_cmd_editor/validators/fill_region_validator.rb +34 -0
  32. data/lib/bitmap_cmd_editor/validators/horizontal_line_validator.rb +38 -0
  33. data/lib/bitmap_cmd_editor/validators/print_table_validator.rb +20 -0
  34. data/lib/bitmap_cmd_editor/validators/validator_herlper.rb +33 -0
  35. data/lib/bitmap_cmd_editor/validators/vertical_line_validator.rb +38 -0
  36. data/lib/bitmap_cmd_editor/version.rb +27 -0
  37. metadata +237 -0
@@ -0,0 +1,38 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ # An intance contains te error_type and a message to the user
5
+ class ErrorMessage
6
+ MESSAGES = {
7
+ :invalid => "This operation is invalid",
8
+ :command_not_exist => "This command is not available, please check the available commands",
9
+ :more_than_max => "the maximun %{obj} allowed are %{max} and you want %{quantity}",
10
+ :less_than_min => "the minimun %{obj} allowed is %{min} and you want %{quantity}",
11
+ :command_wrong_arguments => "this command require %{arguments} arguments",
12
+ :clear_image_wrongs_arguments => "clear image hasn't arguments",
13
+ :print_table_arguments => "print table hasn't arguments",
14
+ :colours_pixel_out_of_range => "a valid %{obj} values are between %{min} and %{max}, and you try %{quantity}",
15
+ :coordinates_are_not_integer => "the coordinates M N must be integers",
16
+ :out_of_range => "a valid %{obj} values are between %{min} and %{max}, and you try %{quantity}",
17
+ :the_colour_is_invalid => "the colour must be a Capital Letter A-Z"
18
+ }
19
+ # initialize the message
20
+ # @param content [String] text message to the user
21
+ # @param error_type [Symbol] to qualifies the error
22
+ # @param args [Hash] to include params in the response
23
+ def initialize(error_type = :invalid, args = {}, content = nil)
24
+ unless content
25
+ @content=MESSAGES[error_type]
26
+ else
27
+ @content = content
28
+ end
29
+ @error_type = error_type
30
+ @args = args
31
+ end
32
+ # @return text message [String] it could contain arguments
33
+ def show_content
34
+ "\n" + @content % @args
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ class FillRegionValidator
5
+ class << self
6
+ # @param args [Array] the command 0=> 'F' and 1=> columns 2 =>rows 3 => colour
7
+ # @param bitmap_columns [Integer] number of columns of the image created
8
+ # @param bitmap_rows [Integer] number of rows of the image created
9
+ def validate(args, bitmap_columns, bitmap_rows)
10
+ begin
11
+ raise FillRegionArgumentError.new(
12
+ ErrorMessage.new(:command_wrong_arguments, {:arguments => 3}).show_content) unless args.count == 4
13
+
14
+ begin
15
+ columns= Integer(args[1])
16
+ rows= Integer(args[2])
17
+ rescue => err
18
+ raise TypeError.new(ErrorMessage.new(:coordinates_are_not_integer).show_content)
19
+ end
20
+ ValidatorHelper.out_of_range('columns',BitmapCmdEditor::MIN_COLUMNS,bitmap_columns,columns)
21
+
22
+ ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,rows)
23
+
24
+ raise TypeError.new(ErrorMessage.new(:the_colour_is_invalid).show_content) unless ('A'..'Z').include?args[3]
25
+
26
+ :valid
27
+ rescue => err
28
+ err.message
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ class HorizontalLineValidator
5
+ class << self
6
+ # @param args [Array] the command 0=> 'H' and 1=> column start 2 => column end 3 => row 4 => colour
7
+ # @param bitmap_columns [Integer] number of columns of the image created
8
+ # @param bitmap_rows [Integer] number of rows of the image created
9
+ def validate(args, bitmap_columns, bitmap_rows)
10
+ begin
11
+ raise HorizontalLineArgumentError.new(
12
+ ErrorMessage.new(:command_wrong_arguments, {:arguments => 4}).show_content) unless args.count == 5
13
+
14
+ begin
15
+ column_start= Integer(args[1])
16
+ column_end= Integer(args[2])
17
+ row= Integer(args[3])
18
+ rescue => err
19
+ raise TypeError.new(ErrorMessage.new(:coordinates_are_not_integer).show_content)
20
+ end
21
+
22
+ ValidatorHelper.out_of_range('columns',BitmapCmdEditor::MIN_COLUMNS,bitmap_columns,column_start)
23
+
24
+ ValidatorHelper.out_of_range('columns',BitmapCmdEditor::MIN_COLUMNS,bitmap_columns,column_end)
25
+
26
+ ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,row)
27
+
28
+ raise TypeError.new(ErrorMessage.new(:the_colour_is_invalid).show_content) unless ('A'..'Z').include?args[4]
29
+
30
+ :valid
31
+ rescue => err
32
+ err.message
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ # To validate a command print table
5
+ class PrintTableValidator
6
+ class << self
7
+ # @param args [Array] the command 0=> 'S'
8
+ def validate(args)
9
+ begin
10
+ raise PrintTableArgumentError.new(
11
+ ErrorMessage.new(:print_table_arguments).show_content) unless args.count == 1
12
+ :valid
13
+ rescue => err
14
+ err.message
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ # To validate a new bitmap image table created
5
+ class ValidatorHelper
6
+ class << self
7
+
8
+ def more_than_max(obj,max,quantity)
9
+ raise MoreColumnsThanAllowed.new(ErrorMessage.new(
10
+ :more_than_max,
11
+ {:obj=> obj , :max => max,:quantity => quantity }
12
+ ).show_content) if quantity > max
13
+
14
+ end
15
+
16
+ def less_than_min(obj,min,quantity)
17
+ raise LessColumnsThanAllowed.new(ErrorMessage.new(
18
+ :less_than_min,
19
+ {:obj=> obj , :min => min,:quantity => quantity }
20
+ ).show_content) if quantity < min
21
+ end
22
+
23
+ def out_of_range(obj,min,max,quantity)
24
+ raise OutOfRange.new(ErrorMessage.new(
25
+ :out_of_range,
26
+ {:obj=> obj , :min => min,:max => max,:quantity => quantity }
27
+ ).show_content) if quantity<min or quantity>max
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module BitmapCmdEditor
2
+ module Validators
3
+ # @author Diego Hernán Piccinini Lagos
4
+ class VerticalLineValidator
5
+ class << self
6
+ # @param args [Array] the command 0=> 'V' and 1=> column 2 => row start 3 => row end 4 => colour
7
+ # @param bitmap_columns [Integer] number of columns of the image created
8
+ # @param bitmap_rows [Integer] number of rows of the image created
9
+ def validate(args, bitmap_columns, bitmap_rows)
10
+ begin
11
+ raise VerticalLineArgumentError.new(
12
+ ErrorMessage.new(:command_wrong_arguments, {:arguments => 4}).show_content) unless args.count == 5
13
+
14
+ begin
15
+ column= Integer(args[1])
16
+ row_start= Integer(args[2])
17
+ row_end= Integer(args[3])
18
+ rescue => err
19
+ raise TypeError.new(ErrorMessage.new(:coordinates_are_not_integer).show_content)
20
+ end
21
+
22
+ ValidatorHelper.out_of_range('columns',BitmapCmdEditor::MIN_COLUMNS,bitmap_columns,column)
23
+
24
+ ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,row_start)
25
+
26
+ ValidatorHelper.out_of_range('rows',BitmapCmdEditor::MIN_ROWS,bitmap_rows,row_end)
27
+
28
+ raise TypeError.new(ErrorMessage.new(:the_colour_is_invalid).show_content) unless ('A'..'Z').include?args[4]
29
+
30
+ :valid
31
+ rescue => err
32
+ err.message
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ Dir[File.join(File.dirname(__FILE__),'*.rb')].each {|file| require file }
2
+ Dir[File.join(File.dirname(__FILE__),'validators','*.rb')].each {|file| require file }
3
+
4
+ module BitmapCmdEditor
5
+ VERSION = "1.0.4"
6
+ COMMANDS = ['X','I','C','L','V','H','F','S']
7
+ MAX_COLUMNS = 250
8
+ MIN_COLUMNS = 1
9
+ MAX_ROWS = 250
10
+ MIN_ROWS = 1
11
+ WELCOME_MESSAGE = <<-EOF
12
+ Welcome to the Bitmap Command Editor
13
+ ------------------------------------
14
+
15
+ Available Commands:
16
+ -------------------
17
+
18
+ I M N - Create a new M x N image with all pixels coloured white (O).
19
+ C - Clears the table, setting all pixels to white (O).
20
+ L X Y C - Colours the pixel (X,Y) with colour C.
21
+ V X Y1 Y2 C - Draw a vertical segment of colour C in column X between rows Y1 and Y2 (inclusive).
22
+ H X1 X2 Y C - Draw a horizontal segment of colour C in row Y between columns X1 and X2 (inclusive).
23
+ F X Y C - Fill the region R with the colour C. R is defined as: Pixel (X,Y) belongs to R. Any other pixel which is the same colour as (X,Y) and shares a common side with any pixel in R also belongs to this region.
24
+ S - Show the contents of the current image
25
+ X - Terminate the session
26
+ EOF
27
+ end
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitmap_cmd_editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Diego Hernán Piccinini Lagos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: shoulda-matchers
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-expectations
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: aruba
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |-
112
+ The input consists of a string containing a sequence of commands, where a command is represented by a single capital letter at the beginning of the line. Parameters of the command are separated by white spaces and they follow the command character.
113
+
114
+ Pixel co-ordinates are a pair of integers: a column number between 1 and 250, and a row number between 1 and 250. Bitmaps starts at coordinates 1,1. Colours are specified by capital letters.
115
+ email:
116
+ - diego@guiasrails.es
117
+ executables:
118
+ - bitmap_cmd_editor
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - .gitignore
123
+ - .travis.yml
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/bitmap_cmd_editor
129
+ - bitmap_cmd_editor.gemspec
130
+ - doc/BitmapCmdEditor.html
131
+ - doc/BitmapCmdEditor/Bitmap.html
132
+ - doc/BitmapCmdEditor/ClearImageArgumentError.html
133
+ - doc/BitmapCmdEditor/Client.html
134
+ - doc/BitmapCmdEditor/ColourPixelArgumentError.html
135
+ - doc/BitmapCmdEditor/CreateImageArgumentError.html
136
+ - doc/BitmapCmdEditor/FillRegionArgumentError.html
137
+ - doc/BitmapCmdEditor/HorizontalLineArgumentError.html
138
+ - doc/BitmapCmdEditor/LessColumnsThanAllowed.html
139
+ - doc/BitmapCmdEditor/LessRowsThanAllowed.html
140
+ - doc/BitmapCmdEditor/MoreColumnsThanAllowed.html
141
+ - doc/BitmapCmdEditor/MoreRowsThanAllowed.html
142
+ - doc/BitmapCmdEditor/NotImplementedCommand.html
143
+ - doc/BitmapCmdEditor/OutOfRange.html
144
+ - doc/BitmapCmdEditor/PrintTableArgumentError.html
145
+ - doc/BitmapCmdEditor/Validators.html
146
+ - doc/BitmapCmdEditor/Validators/ClearImageValidator.html
147
+ - doc/BitmapCmdEditor/Validators/ColourPixelValidator.html
148
+ - doc/BitmapCmdEditor/Validators/CommandValidator.html
149
+ - doc/BitmapCmdEditor/Validators/CreateImageValidator.html
150
+ - doc/BitmapCmdEditor/Validators/ErrorMessage.html
151
+ - doc/BitmapCmdEditor/Validators/FillRegionValidator.html
152
+ - doc/BitmapCmdEditor/Validators/HorizontalLineValidator.html
153
+ - doc/BitmapCmdEditor/Validators/PrintTableValidator.html
154
+ - doc/BitmapCmdEditor/Validators/ValidatorHelper.html
155
+ - doc/BitmapCmdEditor/Validators/VerticalLineValidator.html
156
+ - doc/BitmapCmdEditor/VerticalLineArgumentError.html
157
+ - doc/_index.html
158
+ - doc/class_list.html
159
+ - doc/css/common.css
160
+ - doc/css/full_list.css
161
+ - doc/css/style.css
162
+ - doc/file.README.html
163
+ - doc/file_list.html
164
+ - doc/frames.html
165
+ - doc/index.html
166
+ - doc/js/app.js
167
+ - doc/js/full_list.js
168
+ - doc/js/jquery.js
169
+ - doc/method_list.html
170
+ - doc/top-level-namespace.html
171
+ - features/clear_table.feature
172
+ - features/colours_pixel.feature
173
+ - features/command_bitmap_cmd_editor.feature
174
+ - features/create_bitmap.feature
175
+ - features/draw_horinzontal_segment.feature
176
+ - features/draw_vertical_segment.feature
177
+ - features/fill_region.feature
178
+ - features/show_content.feature
179
+ - features/step_definitions/clear_table_step.rb
180
+ - features/step_definitions/colours_pixel_step.rb
181
+ - features/step_definitions/create_bitmap_step.rb
182
+ - features/support/env.rb
183
+ - lib/bitmap_cmd_editor.rb
184
+ - lib/bitmap_cmd_editor/bitmap.rb
185
+ - lib/bitmap_cmd_editor/client.rb
186
+ - lib/bitmap_cmd_editor/exceptions.rb
187
+ - lib/bitmap_cmd_editor/validators/clear_image_validator.rb
188
+ - lib/bitmap_cmd_editor/validators/colour_pixel_validator.rb
189
+ - lib/bitmap_cmd_editor/validators/command_validator.rb
190
+ - lib/bitmap_cmd_editor/validators/create_image_validator.rb
191
+ - lib/bitmap_cmd_editor/validators/error_message.rb
192
+ - lib/bitmap_cmd_editor/validators/fill_region_validator.rb
193
+ - lib/bitmap_cmd_editor/validators/horizontal_line_validator.rb
194
+ - lib/bitmap_cmd_editor/validators/print_table_validator.rb
195
+ - lib/bitmap_cmd_editor/validators/validator_herlper.rb
196
+ - lib/bitmap_cmd_editor/validators/vertical_line_validator.rb
197
+ - lib/bitmap_cmd_editor/version.rb
198
+ homepage: ''
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - '>='
209
+ - !ruby/object:Gem::Version
210
+ version: 2.0.0
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.4.3
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: Produce a Ruby 2.0 program that simulates a basic interactive bitmap editor.
222
+ Bitmaps are represented as an M x N matrix of pixels with each element representing
223
+ a colour.
224
+ test_files:
225
+ - features/clear_table.feature
226
+ - features/colours_pixel.feature
227
+ - features/command_bitmap_cmd_editor.feature
228
+ - features/create_bitmap.feature
229
+ - features/draw_horinzontal_segment.feature
230
+ - features/draw_vertical_segment.feature
231
+ - features/fill_region.feature
232
+ - features/show_content.feature
233
+ - features/step_definitions/clear_table_step.rb
234
+ - features/step_definitions/colours_pixel_step.rb
235
+ - features/step_definitions/create_bitmap_step.rb
236
+ - features/support/env.rb
237
+ has_rdoc: yard