char_canvas 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dc7a574cfd90e810f803fdce216333826d6ed3d
4
+ data.tar.gz: fd09a8c4a751f3346c6a9e2f8b711795eb2681ff
5
+ SHA512:
6
+ metadata.gz: 779b780dcd72521cb1c5f565bbbf9758d6506608c2f2e35349967bb7e271f12710eb588347933952f639af4e56ef829025402882f0b4cbf8dd6e44b268100fdd
7
+ data.tar.gz: 176243c74928c479a7d5ead44d5ce430802f3e5b96218783c5fa363cde0a4218667e0bea4cd378a94e50fad956e76464787f08e65845a76b94be33d25cc7ceec
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2016, Mariusz Kowalski All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ 3. Neither the name of project nor the names of
14
+ its contributors may be used to endorse or promote products derived from
15
+ this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,15 @@
1
+ # With CharCanvas you can treat terminal like a canvas to paint on.
2
+ # You can put chars on terminal with (line, column) coordinates.
3
+ #
4
+ # Usage:
5
+ # canvas = CharCanvas.new
6
+ # line = 0
7
+ # column = 0
8
+ # 3.times { canvas.insert '*', line += 1, column += 1 }
9
+ # canvas.paint
10
+ #
11
+ # stdout:
12
+ #
13
+ # *
14
+ # *
15
+ # *
@@ -0,0 +1,21 @@
1
+ # documentation in README file
2
+ class CharCanvas
3
+ def initialize
4
+ @canvas = []
5
+ end
6
+
7
+ def insert(string, line, column = 0)
8
+ @canvas[line] ||= []
9
+ string.each_char do |char|
10
+ @canvas[line][column] = char
11
+ column += 1
12
+ end
13
+ end
14
+
15
+ def paint
16
+ @canvas.each do |line|
17
+ line.each { |char| print char || ' ' } if line
18
+ puts
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/char_canvas.rb'
3
+
4
+ class TestCharCanvas < Minitest::Test
5
+ def setup
6
+ @canvas = CharCanvas.new
7
+ end
8
+
9
+ def test_print
10
+ @canvas.insert 'a', 1, 1
11
+ @canvas.insert 'bb', 3
12
+ @canvas.insert 'c', 3, 3
13
+
14
+ result = mock_stdout { @canvas.paint }
15
+
16
+ needed = <<EOT
17
+
18
+ a
19
+
20
+ bb c
21
+ EOT
22
+ assert_equal needed, result
23
+ end
24
+
25
+ private
26
+
27
+ def mock_stdout
28
+ origin_stdout = $stdout
29
+ $stdout = StringIO.new '', 'w'
30
+ yield
31
+ ensure
32
+ fake_out = $stdout
33
+ $stdout = origin_stdout
34
+ return fake_out.string
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: char_canvas
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mariusz Kowalski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ == CharCanvas
15
+ With CharCanvas you can treat terminal like a canvas to paint on.
16
+ You can put chars on terminal with (line, column) coordinates.
17
+ email: mk@devpad.me
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README
24
+ - lib/char_canvas.rb
25
+ - test/test_char_canvas.rb
26
+ homepage: https://github.com/mariusz-kowalski/char_canvas
27
+ licenses:
28
+ - BSD-3-Clause
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.5.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Paint on your terminal.
50
+ test_files: []