bitmap_compiler 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +1 -1
- data/README.md +35 -29
- data/lib/bitmap_compiler.rb +1 -1
- data/lib/bitmap_compiler/cli.rb +2 -3
- data/lib/bitmap_compiler/core/bitmap.rb +1 -0
- data/lib/bitmap_compiler/core/bitmap_actions.rb +9 -9
- data/lib/bitmap_compiler/core/bitmap_controller.rb +15 -4
- data/lib/bitmap_compiler/core/editor.rb +3 -2
- data/lib/bitmap_compiler/core/errors/bitmap_error.rb +10 -4
- data/lib/bitmap_compiler/core/errors/image_not_cleared_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/incorrect_file_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/invalid_coordinates_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/invalid_dimensions_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/invalid_pixel_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/no_image_found_error.rb +9 -3
- data/lib/bitmap_compiler/core/errors/unknown_command_error.rb +9 -3
- data/lib/bitmap_compiler/core/output.rb +1 -0
- data/lib/bitmap_compiler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aafbe44681ab6a478eca0daa40fb3f8f64090dc3
|
4
|
+
data.tar.gz: 0f4e958a789fe9811eea5c5da73b5336c1b59237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39b0bfe42961adc68ca05abe7c9a0d73fa5f06910c61f406b59439a4cedbec3b33c97c7cd03834e0185700a59ed80ff7190a4739ed8910c70ff4be6e1806915e
|
7
|
+
data.tar.gz: 34b775a0ff3ce50a9ed9aca5789473e3e2f099e09f09f9362f25243cd09b4f33cf0799b832275c4aa1cf398a6923f35566a685e6507357df0030500bcb4b4471
|
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,19 @@
|
|
3
3
|
## HEAD Unreleased
|
4
4
|
### Latest update: 2018-08-29
|
5
5
|
|
6
|
+
### Chores
|
7
|
+
|
8
|
+
- [PR #11](https://github.com/vbrazo/bitmap_compiler/pull/11) Add gem version badge [@vbrazo](https://github.com/vbrazo)
|
9
|
+
|
6
10
|
### Documentation
|
7
11
|
|
12
|
+
- [PR #12](https://github.com/vbrazo/bitmap_compiler/pull/12) Add documentation for classes [@vbrazo](https://github.com/vbrazo)
|
8
13
|
- [PR #10](https://github.com/vbrazo/bitmap_compiler/pull/10) Update README.md [@vbrazo](https://github.com/vbrazo)
|
9
14
|
|
10
15
|
### Feature Request/Enhancement
|
11
|
-
|
16
|
+
|
17
|
+
- [PR #14](https://github.com/vbrazo/bitmap_compiler/pull/14) Add CLI missing specs [@vbrazo](https://github.com/vbrazo)
|
18
|
+
- [PR #13](https://github.com/vbrazo/bitmap_compiler/pull/13) Use Error classes instead of printing the output [@vbrazo](https://github.com/vbrazo)
|
12
19
|
- [PR #9](https://github.com/vbrazo/bitmap_compiler/pull/9) Add CLI [@vbrazo](https://github.com/vbrazo)
|
13
20
|
- [PR #8](https://github.com/vbrazo/bitmap_compiler/pull/8) Add Error Pattern and its subclasses [@vbrazo](https://github.com/vbrazo)
|
14
21
|
- [PR #7](https://github.com/vbrazo/bitmap_compiler/pull/7) Add BitmapController actions [@vbrazo](https://github.com/vbrazo)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
[](https://travis-ci.org/vbrazo/bitmap_compiler) [](https://codeclimate.com/github/vbrazo/bitmap_compiler/maintainability) [](https://codeclimate.com/github/vbrazo/bitmap_compiler/test_coverage)
|
1
|
+
# Bitmap Compiler [](https://travis-ci.org/vbrazo/bitmap_compiler) [](https://badge.fury.io/rb/bitmap_compiler) [](https://codeclimate.com/github/vbrazo/bitmap_compiler/maintainability) [](https://codeclimate.com/github/vbrazo/bitmap_compiler/test_coverage)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
This is the Bitmap compiler gem! It aims to build a Bitmap given an input file.
|
3
|
+
This is the Bitmap compiler gem! It aims to build a bitmap given an input file.
|
6
4
|
|
7
5
|
You can check on `spec/support` folder to see examples. The supported commands are:
|
8
6
|
|
9
7
|
```
|
10
|
-
I M N - Create a new M x N image with all pixels coloured white (O)
|
11
|
-
C - Clears the table, setting all pixels to white (O)
|
12
|
-
L X Y C - Colours the pixel (X,Y) with colour C
|
13
|
-
V X Y1 Y2 C - Draw a vertical segment of colour C in column X between rows Y1 and Y2 (inclusive)
|
14
|
-
H X1 X2 Y C - Draw a horizontal segment of colour C in row Y between columns X1 and X2 (inclusive)
|
8
|
+
I M N - Create a new M x N image with all pixels coloured white (O)
|
9
|
+
C - Clears the table, setting all pixels to white (O)
|
10
|
+
L X Y C - Colours the pixel (X,Y) with colour C
|
11
|
+
V X Y1 Y2 C - Draw a vertical segment of colour C in column X between rows Y1 and Y2 (inclusive)
|
12
|
+
H X1 X2 Y C - Draw a horizontal segment of colour C in row Y between columns X1 and X2 (inclusive)
|
15
13
|
S - Show the contents of the current image
|
16
14
|
```
|
17
15
|
|
@@ -41,37 +39,22 @@ OWOOO
|
|
41
39
|
OWOOO
|
42
40
|
```
|
43
41
|
|
44
|
-
## Installation
|
45
|
-
|
46
|
-
Add this line to your application's Gemfile:
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
gem 'bitmap_compiler'
|
50
|
-
```
|
51
|
-
|
52
|
-
And then execute:
|
53
|
-
|
54
|
-
$ bundle
|
55
|
-
|
56
|
-
Or install it yourself as:
|
57
|
-
|
58
|
-
$ gem install bitmap_compiler
|
59
|
-
|
60
42
|
## Usage
|
61
43
|
|
62
|
-
|
44
|
+
### Ruby console
|
45
|
+
|
46
|
+
You can use the application programmatically by installing the gem and using on the Ruby environment (You can run `bin/console` for this). If you want to test the Editor class after launching the console, just run:
|
63
47
|
|
64
48
|
```ruby
|
65
49
|
BitmapCompiler::Core::Editor.new.run('spec/support/show.txt')
|
66
50
|
```
|
67
51
|
|
68
|
-
There is also a CLI provided that can be used.
|
69
|
-
|
70
52
|
### CLI
|
71
53
|
|
72
54
|
The application also has a CLI built-in that can be used directly on any *nix terminal.
|
73
55
|
|
74
56
|
```
|
57
|
+
$ bitmap_compiler process_file -f=spec/support/show.txt
|
75
58
|
$ bitmap_compiler process_file --file=spec/support/show.txt
|
76
59
|
```
|
77
60
|
|
@@ -81,9 +64,31 @@ Use the help command for more information.
|
|
81
64
|
$ bitmap_compiler help process_file
|
82
65
|
```
|
83
66
|
|
67
|
+
### Rails
|
68
|
+
|
69
|
+
Add this line to your application's Gemfile:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
gem 'bitmap_compiler'
|
73
|
+
```
|
74
|
+
|
75
|
+
And then execute:
|
76
|
+
|
77
|
+
$ bundle
|
78
|
+
|
79
|
+
Or install it yourself as:
|
80
|
+
|
81
|
+
$ gem install bitmap_compiler
|
82
|
+
|
83
|
+
After that you should be able to use the `Editor` class in your `rails console` or inside your application:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
BitmapCompiler::Core::Editor.new.run("Specify the file path")
|
87
|
+
```
|
88
|
+
|
84
89
|
## Development
|
85
90
|
|
86
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests.
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests.
|
87
92
|
|
88
93
|
## Contributing
|
89
94
|
|
@@ -92,3 +97,4 @@ See [CONTRIBUTING.md](https://github.com/vbrazo/bitmap_compiler/blob/master/CONT
|
|
92
97
|
## License
|
93
98
|
|
94
99
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
100
|
+
|
data/lib/bitmap_compiler.rb
CHANGED
data/lib/bitmap_compiler/cli.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'thor'
|
4
4
|
|
5
|
-
#
|
5
|
+
# Responsibility: handle the command line interface
|
6
6
|
module BitmapCompiler
|
7
7
|
class CLI < Thor
|
8
8
|
desc 'process_file BITMAP', 'Bitmap compiler via CLI'
|
9
|
+
|
9
10
|
option :file, type: :string, aliases: [:f]
|
10
11
|
|
11
12
|
# CLI method to call the Editor
|
@@ -18,8 +19,6 @@ module BitmapCompiler
|
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
attr_reader :bitmap_compiler
|
22
|
-
|
23
22
|
def bitmap_compiler
|
24
23
|
@bitmap_compiler ||= BitmapCompiler::Core::Editor.new
|
25
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# BitmapCompiler shares role behavior
|
2
1
|
module BitmapCompiler
|
3
2
|
module Core
|
3
|
+
# BitmapActions shares role behavior
|
4
4
|
module BitmapActions
|
5
5
|
def change_color(row:, column:, color: Bitmap::STANDARD_COLOR)
|
6
6
|
return image_not_found unless bitmap
|
@@ -8,7 +8,7 @@ module BitmapCompiler
|
|
8
8
|
if bitmap.change_pixel(row, column, color)
|
9
9
|
return_output
|
10
10
|
else
|
11
|
-
|
11
|
+
raise BitmapCompiler::Core::Errors::InvalidPixelError
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -18,7 +18,7 @@ module BitmapCompiler
|
|
18
18
|
if bitmap.clear
|
19
19
|
return_output
|
20
20
|
else
|
21
|
-
|
21
|
+
raise BitmapCompiler::Core::Errors::ImageNotClearedError
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,7 +27,7 @@ module BitmapCompiler
|
|
27
27
|
args[:height].between?(Bitmap::MIN_HEIGHT, Bitmap::MAX_HEIGHT)
|
28
28
|
return_output(bitmap: Bitmap.new(args[:width], args[:height]))
|
29
29
|
else
|
30
|
-
|
30
|
+
raise BitmapCompiler::Core::Errors::InvalidDimensionsError
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -47,12 +47,12 @@ module BitmapCompiler
|
|
47
47
|
|
48
48
|
return_output
|
49
49
|
else
|
50
|
-
|
50
|
+
raise Errors::InvalidCoordinatesError
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR)
|
55
|
-
|
55
|
+
image_not_found unless bitmap
|
56
56
|
|
57
57
|
if bitmap.valid_vertical_line_coordinates?(row, start_column, end_column)
|
58
58
|
(start_column..end_column).each do |column_index|
|
@@ -61,18 +61,18 @@ module BitmapCompiler
|
|
61
61
|
|
62
62
|
return_output
|
63
63
|
else
|
64
|
-
|
64
|
+
raise BitmapCompiler::Core::Errors::InvalidCoordinatesError
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
def unknown_command
|
69
|
-
|
69
|
+
raise BitmapCompiler::Core::Errors::UnknownCommandError
|
70
70
|
end
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def image_not_found
|
75
|
-
|
75
|
+
raise BitmapCompiler::Core::Errors::NoImageFoundError
|
76
76
|
end
|
77
77
|
|
78
78
|
def return_output(args = {})
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module BitmapCompiler
|
4
4
|
module Core
|
5
|
+
# Responsibility: execute commands
|
5
6
|
class BitmapController
|
6
7
|
include BitmapActions
|
7
8
|
|
@@ -19,10 +20,12 @@ module BitmapCompiler
|
|
19
20
|
create_bitmap(bitmap_hash)
|
20
21
|
when 'C'
|
21
22
|
clear
|
23
|
+
when 'L'
|
24
|
+
change_color(pixel_hash)
|
22
25
|
when 'V'
|
23
|
-
change_vertical_line(
|
26
|
+
change_vertical_line(vertical_line_hash)
|
24
27
|
when 'H'
|
25
|
-
change_horizontal_line(
|
28
|
+
change_horizontal_line(horizontal_line_hash)
|
26
29
|
when 'S'
|
27
30
|
print
|
28
31
|
else
|
@@ -39,7 +42,7 @@ module BitmapCompiler
|
|
39
42
|
}
|
40
43
|
end
|
41
44
|
|
42
|
-
def
|
45
|
+
def horizontal_line_hash
|
43
46
|
{
|
44
47
|
start_row: Integer(input[1]),
|
45
48
|
end_row: Integer(input[2]),
|
@@ -48,7 +51,15 @@ module BitmapCompiler
|
|
48
51
|
}
|
49
52
|
end
|
50
53
|
|
51
|
-
def
|
54
|
+
def pixel_hash
|
55
|
+
{
|
56
|
+
row: Integer(input[1]),
|
57
|
+
column: Integer(input[2]),
|
58
|
+
color: input[3]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def vertical_line_hash
|
52
63
|
{
|
53
64
|
row: Integer(input[1]),
|
54
65
|
start_column: Integer(input[2]),
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module BitmapCompiler
|
4
4
|
module Core
|
5
|
+
# Responsibility: process the files
|
5
6
|
class Editor
|
6
7
|
attr_reader :bitmap
|
7
8
|
|
@@ -10,7 +11,7 @@ module BitmapCompiler
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def run(file)
|
13
|
-
raise IncorrectFileError if file.nil? || !File.exist?(file)
|
14
|
+
raise BitmapCompiler::Core::Errors::IncorrectFileError if file.nil? || !File.exist?(file)
|
14
15
|
|
15
16
|
File.open(file).each { |line| process_line(line.chomp) }
|
16
17
|
end
|
@@ -26,7 +27,7 @@ module BitmapCompiler
|
|
26
27
|
private
|
27
28
|
|
28
29
|
def bitmap_controller
|
29
|
-
BitmapController.new(bitmap)
|
30
|
+
@bitmap_controller ||= BitmapController.new(bitmap)
|
30
31
|
end
|
31
32
|
|
32
33
|
def execute(input)
|
@@ -1,8 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# Template Method Pattern for our Error classes
|
4
|
+
module BitmapCompiler
|
5
|
+
module Core
|
6
|
+
module Errors
|
7
|
+
class BitmapError < StandardError
|
8
|
+
def message
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class ImageNotClearedError < BitmapError
|
7
|
+
def message
|
8
|
+
'Unable to clear Image'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class IncorrectFileError < BitmapError
|
7
|
+
def message
|
8
|
+
'Incorrect File'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class InvalidCoordinatesError < BitmapError
|
7
|
+
def message
|
8
|
+
'Invalid Coordinates'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class InvalidDimensionsError < BitmapError
|
7
|
+
def message
|
8
|
+
'Invalid height and/or width'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class InvalidPixelError < BitmapError
|
7
|
+
def message
|
8
|
+
'Invalid Pixel'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class NoImageFoundError < BitmapError
|
7
|
+
def message
|
8
|
+
'Image Not Found'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
module Errors
|
6
|
+
class UnknownCommandError < BitmapError
|
7
|
+
def message
|
8
|
+
'Unknown Command'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitmap_compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitor Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|