term-art 1.0 → 1.1

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/term-art.rb +62 -0
  3. metadata +5 -6
  4. data/lib/board.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8e74d6629cfac4bbba97023bd78cbdfc395a1489
4
- data.tar.gz: 68ab53ae9126c50291a0a95e180e3593d322f6cd
2
+ SHA256:
3
+ metadata.gz: d328c3c14f747c509d0137a84114b477baa539585400269da36dbd014ab15bb0
4
+ data.tar.gz: 499c1d929406366815e23c134b6d49f806b974737dff116a9afa5fe9745339b7
5
5
  SHA512:
6
- metadata.gz: 64890241e4446190ec3b00a33573e0c06f397b2578979ac81e28879ea2788b35edb5a8fdba9a1b0933d798e8a1c3c625adb41bbcc250b0906f053ee2eb160916
7
- data.tar.gz: ea833099a448a5fcdb34c9fb0bda4f52845e42ff96462c23c91b12434a147cf3a7d67edb4d7057ee287f90a596e07b00debf2535f14062970b0437aac7372d1a
6
+ metadata.gz: 0f90d76ae3e216318270cfcc00e9e580ad8d7a9af86d0f24adcc1c1a838907b7aea71ba9c19e7b9e9023ff31df01fd6c4acfb90c8706fcfbd703ba2566d42214
7
+ data.tar.gz: ecfb4fb94a69c85cddf738adbe8d0d06398fb21e505d1ad98ab9659bc06fe32525de9951a590564ea67f620585919e12c71e692131495f5fd164f9be730abc9f
data/lib/term-art.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'hue'
2
+
3
+ module TermArt
4
+ class Chart
5
+ STYLES = {
6
+ simple: '┌┬┐├┼┤└┴┘│─',
7
+ double: '╔╦╗╠╬╣╚╩╝║═'
8
+ }.freeze
9
+
10
+ attr_reader :lines
11
+
12
+ def initialize(lines)
13
+ @lines = lines
14
+ end
15
+
16
+ def draw(params)
17
+ params[:color] = :white if params[:color].nil?
18
+ style = style(params)
19
+ lengths = columns_length
20
+ horizontal_columns_separators = horizontal_columns_separators(lengths, style)
21
+
22
+ up = style[0] + horizontal_columns_separators.join(style[1]) + style[2]
23
+ separator = style[3] + horizontal_columns_separators.join(style[4]) + style[5]
24
+ down = style[6] + horizontal_columns_separators.join(style[7]) + style[8]
25
+
26
+ formatted_lines = []
27
+
28
+ @lines.each_index do |line_index|
29
+ line = @lines[line_index]
30
+ line = line.map { |item| item.center(lengths[line.index(item)]) }
31
+
32
+ vertical_separator = style[-2]
33
+ line = vertical_separator + ' ' +
34
+ line.join(" #{vertical_separator} ") + ' ' +vertical_separator.to_s
35
+
36
+ formatted_lines << line
37
+ end
38
+
39
+ [up, formatted_lines.join("\n#{separator}\n"), down].join("\n")
40
+ end
41
+
42
+ private
43
+
44
+ def columns_length
45
+ @lines.transpose.map do |column|
46
+ column.max_by(&:size).size
47
+ end
48
+ end
49
+
50
+ def horizontal_columns_separators(lengths, style)
51
+ lengths.dup.map do |column_size|
52
+ style[-1] * (column_size + 2)
53
+ end
54
+ end
55
+
56
+ def style(params)
57
+ STYLES[params[:style]].chars.map do |separator|
58
+ separator.send(params[:color]) + ''.white
59
+ end
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: term-art
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - AnanaGame
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-04 00:00:00.000000000 Z
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make ascii art boards
14
14
  email: gameanana@gmail.com
@@ -16,10 +16,9 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/board.rb
19
+ - lib/term-art.rb
20
20
  homepage:
21
- licenses:
22
- - MIT
21
+ licenses: []
23
22
  metadata: {}
24
23
  post_install_message:
25
24
  rdoc_options: []
@@ -37,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
36
  version: '0'
38
37
  requirements: []
39
38
  rubyforge_project:
40
- rubygems_version: 2.6.14
39
+ rubygems_version: 2.7.6
41
40
  signing_key:
42
41
  specification_version: 4
43
42
  summary: Boards
data/lib/board.rb DELETED
@@ -1,64 +0,0 @@
1
- module TermArt
2
-
3
- class Board
4
-
5
- STYLES = {
6
- # Name => Separators
7
- :simple => '┌┬┐├┼┤└┴┘│─',
8
- :double => '╔╦╗╠╬╣╚╩╝║═'
9
- }
10
-
11
- COLOR = {
12
- :default => 39, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36
13
- }
14
-
15
- attr_reader :titles, :lines
16
-
17
- def initialize(titles, lines)
18
- @titles = titles
19
- @lines = lines
20
- end
21
-
22
- def draw(style, color = :default) # Differents styles
23
- color = "\e[#{COLOR[color]}m"
24
- style = STYLES[style].chars.map{ |separator| "#{color}#{separator}\e[39m" }
25
-
26
- # Get all the sizes of columns
27
- max_lengths = @lines.dup.push(@titles).transpose.map do |column|
28
- column.max_by(&:size).size
29
- end
30
-
31
- # Get the horizontal separators
32
- horizontal_columns = []
33
- max_lengths.each do |column_size|
34
- horizontal_columns << style[-1] * (column_size + 2)
35
- end
36
-
37
- # Get all separators
38
- up = style[0] + horizontal_columns.join(style[1]) + style[2]
39
- separator = style[3] + horizontal_columns.join(style[4]) + style[5]
40
- down = style[6] + horizontal_columns.join(style[7]) + style[8]
41
-
42
- formatted_lines = []
43
-
44
- all_lines = @lines
45
- .dup
46
- .unshift(titles)
47
-
48
- all_lines.each_index do |line_index| # Center all line items
49
- line = all_lines[line_index]
50
- line = line.map { |item| item.center(max_lengths[line.index(item)])}
51
-
52
- # Format the line with vertical separator
53
- vertical_separator = style[-2]
54
- line = "#{vertical_separator} #{line.join(" #{vertical_separator} ")} #{vertical_separator}"
55
-
56
- formatted_lines << line
57
- end
58
-
59
- [up, formatted_lines.join("\n#{separator}\n"), down].join("\n")
60
- end
61
-
62
- end
63
-
64
- end