bitmap_compiler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +20 -0
- data/CONTRIBUTING.md +27 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/bitmap_compiler.gemspec +32 -0
- data/docs/Technical Test.pdf +0 -0
- data/docs/bitmap_editor-master.zip +0 -0
- data/exe/bitmap_compiler +6 -0
- data/lib/bitmap_compiler.rb +21 -0
- data/lib/bitmap_compiler/cli.rb +27 -0
- data/lib/bitmap_compiler/core/bitmap.rb +67 -0
- data/lib/bitmap_compiler/core/bitmap_actions.rb +83 -0
- data/lib/bitmap_compiler/core/bitmap_controller.rb +61 -0
- data/lib/bitmap_compiler/core/editor.rb +37 -0
- data/lib/bitmap_compiler/core/errors/bitmap_error.rb +8 -0
- data/lib/bitmap_compiler/core/errors/image_not_cleared_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/incorrect_file_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/invalid_coordinates_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/invalid_dimensions_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/invalid_pixel_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/no_image_found_error.rb +7 -0
- data/lib/bitmap_compiler/core/errors/unknown_command_error.rb +7 -0
- data/lib/bitmap_compiler/core/output.rb +21 -0
- data/lib/bitmap_compiler/version.rb +3 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b886f6b74288b45633834252af0f68cf8c132c2
|
4
|
+
data.tar.gz: e917bfbf7d12ac7c0c3b9a4ff59b8b543a4e6af7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5cf3c89cf783bb2684d2fe5bd6587508aa592782c6122a39234b87225b27c17a3de3a04118c9c1f9cd82cf25ea486a993424fcdf2491ee97db75bb1d9001a27
|
7
|
+
data.tar.gz: 84de4e9ceca35c8c0ca0c1816a44960b9ecde19cd8a5b790411bc9fc4ed37a7811e8e46a00805a66320ed6a5c1cc0da944eceab9214442bad5ba341404318c77
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 100
|
3
|
+
|
4
|
+
Metrics/MethodLength:
|
5
|
+
Max: 20
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Max: 20
|
9
|
+
|
10
|
+
Layout/SpaceBeforeSemicolon:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/RedundantReturn:
|
17
|
+
AllowMultipleReturnValues: true
|
18
|
+
|
19
|
+
Style/PercentLiteralDelimiters:
|
20
|
+
PreferredDelimiters:
|
21
|
+
default: ()
|
22
|
+
'%w': '()'
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=88cdb5fb80b4f1a45c75f3cd6b85536d2aa90d2a5771c50e2a787dc6033bfb3b
|
4
|
+
sudo: false
|
5
|
+
language: ruby
|
6
|
+
cache: bundler
|
7
|
+
rvm:
|
8
|
+
- 2.3.0
|
9
|
+
- 2.4.4
|
10
|
+
- 2.5.1
|
11
|
+
- ruby-head
|
12
|
+
before_script:
|
13
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
14
|
+
- chmod +x ./cc-test-reporter
|
15
|
+
- ./cc-test-reporter before-build
|
16
|
+
script: bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## HEAD Unreleased
|
4
|
+
### Latest update: 2018-08-29
|
5
|
+
|
6
|
+
### Documentation
|
7
|
+
|
8
|
+
- [PR #10](https://github.com/vbrazo/bitmap_compiler/pull/10) Update README.md [@vbrazo](https://github.com/vbrazo)
|
9
|
+
|
10
|
+
### Feature Request/Enhancement
|
11
|
+
|
12
|
+
- [PR #9](https://github.com/vbrazo/bitmap_compiler/pull/9) Add CLI [@vbrazo](https://github.com/vbrazo)
|
13
|
+
- [PR #8](https://github.com/vbrazo/bitmap_compiler/pull/8) Add Error Pattern and its subclasses [@vbrazo](https://github.com/vbrazo)
|
14
|
+
- [PR #7](https://github.com/vbrazo/bitmap_compiler/pull/7) Add BitmapController actions [@vbrazo](https://github.com/vbrazo)
|
15
|
+
- [PR #6](https://github.com/vbrazo/bitmap_compiler/pull/6) Add Bitmap and BitmapController objects [@vbrazo](https://github.com/vbrazo)
|
16
|
+
- [PR #5](https://github.com/vbrazo/bitmap_compiler/pull/5) Add Editor object [@vbrazo](https://github.com/vbrazo)
|
17
|
+
- [PR #4](https://github.com/vbrazo/bitmap_compiler/pull/4) Add Output object [@vbrazo](https://github.com/vbrazo)
|
18
|
+
- [PR #3](https://github.com/vbrazo/bitmap_compiler/pull/3) Add rubocop [@vbrazo](https://github.com/vbrazo)
|
19
|
+
- [PR #2](https://github.com/vbrazo/bitmap_compiler/pull/2) Add Travis CI and Code Climate [@vbrazo](https://github.com/vbrazo)
|
20
|
+
- [PR #1](https://github.com/vbrazo/bitmap_compiler/pull/1) Set up project [@vbrazo](https://github.com/vbrazo)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
We love pull requests. Here's a quick guide:
|
2
|
+
|
3
|
+
1. Fork the repo.
|
4
|
+
|
5
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `bundle exec rspec`
|
6
|
+
|
7
|
+
3. Please add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test! We use [Rspec](http://rspec.info/) in this project.
|
8
|
+
|
9
|
+
4. Push to your fork and submit a pull request.
|
10
|
+
|
11
|
+
### Github Flow for contributors and collaborators
|
12
|
+
|
13
|
+
For those of you with commit access, please check out Scott Chacon's blog post about [github flow](http://scottchacon.com/2011/08/31/github-flow.html)
|
14
|
+
|
15
|
+
> * Anything in the master branch is deployable
|
16
|
+
> * To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes)
|
17
|
+
> * Commit to that branch locally and regularly push your work to the same named branch on the server
|
18
|
+
> * When you need feedback or help, or you think the branch is ready for merging, open a pull request
|
19
|
+
> * After someone else has reviewed and signed off on the feature, you can merge it into master
|
20
|
+
|
21
|
+
If you're reviewing a PR, you should ask youserlf:
|
22
|
+
> * Does it work as described? A PR should have a great description.
|
23
|
+
> * Is it understandable?
|
24
|
+
> * Is it well implemented?
|
25
|
+
> * Is it well tested?
|
26
|
+
> * Is it well documented?
|
27
|
+
> * Is it following the structure of the project?
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bitmap_compiler (0.1.0)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
concurrent-ruby (1.0.5)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.3.1)
|
14
|
+
faker (1.9.1)
|
15
|
+
i18n (>= 0.7)
|
16
|
+
i18n (1.1.0)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
jaro_winkler (1.5.1)
|
19
|
+
json (2.1.0)
|
20
|
+
parallel (1.12.1)
|
21
|
+
parser (2.5.1.2)
|
22
|
+
ast (~> 2.4.0)
|
23
|
+
powerpack (0.1.2)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (12.3.1)
|
26
|
+
rspec (3.8.0)
|
27
|
+
rspec-core (~> 3.8.0)
|
28
|
+
rspec-expectations (~> 3.8.0)
|
29
|
+
rspec-mocks (~> 3.8.0)
|
30
|
+
rspec-core (3.8.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-expectations (3.8.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-mocks (3.8.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-support (3.8.0)
|
39
|
+
rubocop (0.58.2)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.5, != 2.5.1.1)
|
43
|
+
powerpack (~> 0.1)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
47
|
+
ruby-progressbar (1.10.0)
|
48
|
+
simplecov (0.16.1)
|
49
|
+
docile (~> 1.1)
|
50
|
+
json (>= 1.8, < 3)
|
51
|
+
simplecov-html (~> 0.10.0)
|
52
|
+
simplecov-html (0.10.2)
|
53
|
+
thor (0.20.0)
|
54
|
+
unicode-display_width (1.4.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bitmap_compiler!
|
61
|
+
bundler
|
62
|
+
faker
|
63
|
+
rake
|
64
|
+
rspec (~> 3.0)
|
65
|
+
rubocop
|
66
|
+
simplecov
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
1.16.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Vitor Oliveira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/vbrazo/bitmap_compiler.svg?branch=master)](https://travis-ci.org/vbrazo/bitmap_compiler) [![Maintainability](https://api.codeclimate.com/v1/badges/1cc557f6b323fd458c12/maintainability)](https://codeclimate.com/github/vbrazo/bitmap_compiler/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/1cc557f6b323fd458c12/test_coverage)](https://codeclimate.com/github/vbrazo/bitmap_compiler/test_coverage)
|
2
|
+
|
3
|
+
# BitmapCompiler
|
4
|
+
|
5
|
+
This is the Bitmap compiler gem! It aims to build a Bitmap given an input file.
|
6
|
+
|
7
|
+
You can check on `spec/support` folder to see examples. The supported commands are:
|
8
|
+
|
9
|
+
```
|
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).
|
15
|
+
S - Show the contents of the current image
|
16
|
+
```
|
17
|
+
|
18
|
+
* The maximum size allowed when creating an Image is 250x250
|
19
|
+
* Colors must be a single capital character A-Z
|
20
|
+
|
21
|
+
## Example of file
|
22
|
+
|
23
|
+
#### Input: show.txt
|
24
|
+
|
25
|
+
```
|
26
|
+
I 5 6
|
27
|
+
L 1 3 A
|
28
|
+
V 2 3 6 W
|
29
|
+
H 3 5 2 Z
|
30
|
+
S
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Output
|
34
|
+
|
35
|
+
```
|
36
|
+
OOOOO
|
37
|
+
OOZZZ
|
38
|
+
AWOOO
|
39
|
+
OWOOO
|
40
|
+
OWOOO
|
41
|
+
OWOOO
|
42
|
+
```
|
43
|
+
|
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
|
+
## Usage
|
61
|
+
|
62
|
+
You can use the application programmatically by installing the gem and using on the Ruby environment (You can run `bin/console` for this). Check the examples folder for more examples.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
BitmapCompiler::Core::Editor.new.run('spec/support/show.txt')
|
66
|
+
```
|
67
|
+
|
68
|
+
There is also a CLI provided that can be used.
|
69
|
+
|
70
|
+
### CLI
|
71
|
+
|
72
|
+
The application also has a CLI built-in that can be used directly on any *nix terminal.
|
73
|
+
|
74
|
+
```
|
75
|
+
$ bitmap_compiler process_file --file=spec/support/show.txt
|
76
|
+
```
|
77
|
+
|
78
|
+
Use the help command for more information.
|
79
|
+
|
80
|
+
```
|
81
|
+
$ bitmap_compiler help process_file
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
## Contributing
|
89
|
+
|
90
|
+
See [CONTRIBUTING.md](https://github.com/vbrazo/bitmap_compiler/blob/master/CONTRIBUTING.md).
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'bitmap_compiler/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'bitmap_compiler'
|
10
|
+
spec.version = BitmapCompiler::VERSION
|
11
|
+
spec.authors = ['Vitor Oliveira']
|
12
|
+
spec.email = ['vbrazo@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'Bitmap Compiler API Ruby Client'
|
15
|
+
spec.description = 'Official Ruby Bitmap Compiler'
|
16
|
+
spec.homepage = 'https://github.com/vbrazo/bitmap_compiler'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'thor'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'faker'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_development_dependency 'simplecov'
|
32
|
+
end
|
Binary file
|
Binary file
|
data/exe/bitmap_compiler
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bitmap_compiler/cli'
|
4
|
+
require 'bitmap_compiler/version'
|
5
|
+
|
6
|
+
require 'bitmap_compiler/core/bitmap'
|
7
|
+
require 'bitmap_compiler/core/bitmap_actions'
|
8
|
+
require 'bitmap_compiler/core/bitmap_controller'
|
9
|
+
require 'bitmap_compiler/core/errors/bitmap_error'
|
10
|
+
require 'bitmap_compiler/core/errors/image_not_cleared_error'
|
11
|
+
require 'bitmap_compiler/core/errors/incorrect_file_error'
|
12
|
+
require 'bitmap_compiler/core/errors/invalid_coordinates_error'
|
13
|
+
require 'bitmap_compiler/core/errors/invalid_dimensions_error'
|
14
|
+
require 'bitmap_compiler/core/errors/invalid_pixel_error'
|
15
|
+
require 'bitmap_compiler/core/errors/no_image_found_error'
|
16
|
+
require 'bitmap_compiler/core/errors/unknown_command_error'
|
17
|
+
require 'bitmap_compiler/core/editor'
|
18
|
+
require 'bitmap_compiler/core/output'
|
19
|
+
|
20
|
+
# Bitmap gem global module
|
21
|
+
module BitmapCompiler; end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
# Class responsible for handle the command line interface
|
6
|
+
module BitmapCompiler
|
7
|
+
class CLI < Thor
|
8
|
+
desc 'process_file BITMAP', 'Bitmap compiler via CLI'
|
9
|
+
option :file, type: :string, aliases: [:f]
|
10
|
+
|
11
|
+
# CLI method to call the Editor
|
12
|
+
def process_file
|
13
|
+
bitmap_compiler.run(options[:file])
|
14
|
+
rescue StandardError => e
|
15
|
+
warn "ERROR: #{e.message}"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :bitmap_compiler
|
22
|
+
|
23
|
+
def bitmap_compiler
|
24
|
+
@bitmap_compiler ||= BitmapCompiler::Core::Editor.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module BitmapCompiler
|
2
|
+
module Core
|
3
|
+
class Bitmap
|
4
|
+
MIN_WIDTH = MIN_HEIGHT = 1
|
5
|
+
MAX_WIDTH = MAX_HEIGHT = 250
|
6
|
+
STANDARD_COLOR = 'O'.freeze
|
7
|
+
|
8
|
+
attr_reader :width, :height, :cells
|
9
|
+
|
10
|
+
def initialize(width, height, cells: nil)
|
11
|
+
@height = Integer(height)
|
12
|
+
@width = Integer(width)
|
13
|
+
@cells = cells
|
14
|
+
|
15
|
+
clear if cells.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def change_pixel(row, column, color)
|
19
|
+
return false unless valid_coordinate?(row, column)
|
20
|
+
|
21
|
+
cells[row - 1][column - 1] = color
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
@cells = initialize_matrix
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize_matrix
|
29
|
+
Array.new(width) { Array.new(height) { STANDARD_COLOR } }
|
30
|
+
end
|
31
|
+
|
32
|
+
def print
|
33
|
+
''.tap do |output|
|
34
|
+
(0..cells[0].length - 1).each do |column_index|
|
35
|
+
(0..cells.length - 1).each do |row_index|
|
36
|
+
output << cells[row_index][column_index]
|
37
|
+
end
|
38
|
+
|
39
|
+
output << "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def valid_vertical_line_coordinates?(row, start_column, end_column)
|
45
|
+
valid_row_index?(row) && valid_column_index?(start_column) &&
|
46
|
+
valid_column_index?(end_column) && start_column <= end_column
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid_horizontal_line_coordinates?(column, start_row, end_row)
|
50
|
+
valid_row_index?(end_row) && valid_row_index?(start_row) &&
|
51
|
+
valid_column_index?(column) && start_row <= end_row
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_coordinate?(row, column)
|
55
|
+
valid_row_index?(row) && valid_column_index?(column)
|
56
|
+
end
|
57
|
+
|
58
|
+
def valid_column_index?(column)
|
59
|
+
column.between?(1, height)
|
60
|
+
end
|
61
|
+
|
62
|
+
def valid_row_index?(row)
|
63
|
+
row.between?(1, width)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# BitmapCompiler shares role behavior
|
2
|
+
module BitmapCompiler
|
3
|
+
module Core
|
4
|
+
module BitmapActions
|
5
|
+
def change_color(row:, column:, color: Bitmap::STANDARD_COLOR)
|
6
|
+
return image_not_found unless bitmap
|
7
|
+
|
8
|
+
if bitmap.change_pixel(row, column, color)
|
9
|
+
return_output
|
10
|
+
else
|
11
|
+
return_output(message: InvalidPixelError.new.message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear
|
16
|
+
return image_not_found unless bitmap
|
17
|
+
|
18
|
+
if bitmap.clear
|
19
|
+
return_output
|
20
|
+
else
|
21
|
+
return_output(message: ImageNotClearedError.new.message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_bitmap(args)
|
26
|
+
if args[:width].between?(Bitmap::MIN_WIDTH, Bitmap::MAX_WIDTH) &&
|
27
|
+
args[:height].between?(Bitmap::MIN_HEIGHT, Bitmap::MAX_HEIGHT)
|
28
|
+
return_output(bitmap: Bitmap.new(args[:width], args[:height]))
|
29
|
+
else
|
30
|
+
return_output(message: InvalidDimensionsError.new.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def print
|
35
|
+
return image_not_found unless bitmap
|
36
|
+
|
37
|
+
return_output(message: bitmap.print)
|
38
|
+
end
|
39
|
+
|
40
|
+
def change_horizontal_line(column:, start_row:, end_row:, color: Bitmap::STANDARD_COLOR)
|
41
|
+
return image_not_found unless bitmap
|
42
|
+
|
43
|
+
if bitmap.valid_horizontal_line_coordinates?(column, start_row, end_row)
|
44
|
+
(start_row..end_row).each do |row_index|
|
45
|
+
bitmap.change_pixel(row_index, column, color)
|
46
|
+
end
|
47
|
+
|
48
|
+
return_output
|
49
|
+
else
|
50
|
+
return_output(message: InvalidCoordinatesError.new.message)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR)
|
55
|
+
return image_not_found unless bitmap
|
56
|
+
|
57
|
+
if bitmap.valid_vertical_line_coordinates?(row, start_column, end_column)
|
58
|
+
(start_column..end_column).each do |column_index|
|
59
|
+
bitmap.change_pixel(row, column_index, color)
|
60
|
+
end
|
61
|
+
|
62
|
+
return_output
|
63
|
+
else
|
64
|
+
return_output(message: InvalidCoordinatesError.new.message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def unknown_command
|
69
|
+
return_output(message: UnknownCommandError.new.message)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def image_not_found
|
75
|
+
return_output(message: NoImageFoundError.new.message)
|
76
|
+
end
|
77
|
+
|
78
|
+
def return_output(args = {})
|
79
|
+
Output.new(bitmap: args[:bitmap], message: args[:message])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
class BitmapController
|
6
|
+
include BitmapActions
|
7
|
+
|
8
|
+
def initialize(bitmap = nil)
|
9
|
+
@bitmap = bitmap
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :bitmap, :input
|
13
|
+
|
14
|
+
def execute_command(input)
|
15
|
+
@input = input.split
|
16
|
+
|
17
|
+
case input[0]
|
18
|
+
when 'I'
|
19
|
+
create_bitmap(bitmap_hash)
|
20
|
+
when 'C'
|
21
|
+
clear
|
22
|
+
when 'V'
|
23
|
+
change_vertical_line(change_vertical_line_hash)
|
24
|
+
when 'H'
|
25
|
+
change_horizontal_line(change_horizontal_line_hash)
|
26
|
+
when 'S'
|
27
|
+
print
|
28
|
+
else
|
29
|
+
unknown_command
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def bitmap_hash
|
36
|
+
{
|
37
|
+
width: Integer(input[1]),
|
38
|
+
height: Integer(input[2])
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def change_horizontal_line_hash
|
43
|
+
{
|
44
|
+
start_row: Integer(input[1]),
|
45
|
+
end_row: Integer(input[2]),
|
46
|
+
column: Integer(input[3]),
|
47
|
+
color: input[4]
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def change_vertical_line_hash
|
52
|
+
{
|
53
|
+
row: Integer(input[1]),
|
54
|
+
start_column: Integer(input[2]),
|
55
|
+
end_column: Integer(input[3]),
|
56
|
+
color: input[4]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
class Editor
|
6
|
+
attr_reader :bitmap
|
7
|
+
|
8
|
+
def initialize(bitmap: nil)
|
9
|
+
@bitmap = bitmap
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(file)
|
13
|
+
raise IncorrectFileError if file.nil? || !File.exist?(file)
|
14
|
+
|
15
|
+
File.open(file).each { |line| process_line(line.chomp) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_line(input)
|
19
|
+
output = execute(input)
|
20
|
+
|
21
|
+
@bitmap = output.bitmap if output.bitmap
|
22
|
+
|
23
|
+
output.print
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def bitmap_controller
|
29
|
+
BitmapController.new(bitmap)
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute(input)
|
33
|
+
bitmap_controller.execute_command(input)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitmapCompiler
|
4
|
+
module Core
|
5
|
+
class Output
|
6
|
+
attr_reader :bitmap, :message
|
7
|
+
|
8
|
+
def initialize(args = {})
|
9
|
+
@bitmap = args[:bitmap]
|
10
|
+
@message = args[:message]
|
11
|
+
end
|
12
|
+
|
13
|
+
def print
|
14
|
+
return unless message
|
15
|
+
|
16
|
+
$stdout.write message.chomp ''
|
17
|
+
$stdout.write "\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitmap_compiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitor Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faker
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
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: simplecov
|
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: Official Ruby Bitmap Compiler
|
112
|
+
email:
|
113
|
+
- vbrazo@gmail.com
|
114
|
+
executables:
|
115
|
+
- bitmap_compiler
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CHANGELOG.md
|
124
|
+
- CONTRIBUTING.md
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- bin/console
|
131
|
+
- bin/setup
|
132
|
+
- bitmap_compiler.gemspec
|
133
|
+
- docs/Technical Test.pdf
|
134
|
+
- docs/bitmap_editor-master.zip
|
135
|
+
- exe/bitmap_compiler
|
136
|
+
- lib/bitmap_compiler.rb
|
137
|
+
- lib/bitmap_compiler/cli.rb
|
138
|
+
- lib/bitmap_compiler/core/bitmap.rb
|
139
|
+
- lib/bitmap_compiler/core/bitmap_actions.rb
|
140
|
+
- lib/bitmap_compiler/core/bitmap_controller.rb
|
141
|
+
- lib/bitmap_compiler/core/editor.rb
|
142
|
+
- lib/bitmap_compiler/core/errors/bitmap_error.rb
|
143
|
+
- lib/bitmap_compiler/core/errors/image_not_cleared_error.rb
|
144
|
+
- lib/bitmap_compiler/core/errors/incorrect_file_error.rb
|
145
|
+
- lib/bitmap_compiler/core/errors/invalid_coordinates_error.rb
|
146
|
+
- lib/bitmap_compiler/core/errors/invalid_dimensions_error.rb
|
147
|
+
- lib/bitmap_compiler/core/errors/invalid_pixel_error.rb
|
148
|
+
- lib/bitmap_compiler/core/errors/no_image_found_error.rb
|
149
|
+
- lib/bitmap_compiler/core/errors/unknown_command_error.rb
|
150
|
+
- lib/bitmap_compiler/core/output.rb
|
151
|
+
- lib/bitmap_compiler/version.rb
|
152
|
+
homepage: https://github.com/vbrazo/bitmap_compiler
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.5.1
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Bitmap Compiler API Ruby Client
|
176
|
+
test_files: []
|