term-art 1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/board.rb +64 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e74d6629cfac4bbba97023bd78cbdfc395a1489
4
+ data.tar.gz: 68ab53ae9126c50291a0a95e180e3593d322f6cd
5
+ SHA512:
6
+ metadata.gz: 64890241e4446190ec3b00a33573e0c06f397b2578979ac81e28879ea2788b35edb5a8fdba9a1b0933d798e8a1c3c625adb41bbcc250b0906f053ee2eb160916
7
+ data.tar.gz: ea833099a448a5fcdb34c9fb0bda4f52845e42ff96462c23c91b12434a147cf3a7d67edb4d7057ee287f90a596e07b00debf2535f14062970b0437aac7372d1a
data/lib/board.rb ADDED
@@ -0,0 +1,64 @@
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
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: term-art
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - AnanaGame
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Make ascii art boards
14
+ email: gameanana@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/board.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Boards
44
+ test_files: []