cli-table 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cli-table.rb +83 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 28051eeb3d368afcf40bd6c7e54b3e7edbfd12230d77b4ca119ca70a9058df3b
|
4
|
+
data.tar.gz: 9315767f4120937775524b254c9b16e13d8dc531eac5ae942cda74c0ec89c6a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ef1c65fa870f8d4fd19a7aeea13316f197b4cda652de6ee6e2a94690a8381a673be7394faea9f8bd4cabbe85414db973f305c9617e8772ed3411d8e38c48803
|
7
|
+
data.tar.gz: 957893c6046bdf9824cc54991f6b4d1c7e58c551f62406a9df480b7dc97d093e627157abfc682ff3233d24485ba6807b0ced68377e19f6d5eb1eb9bcc8c12b9a
|
data/lib/cli-table.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
class Table
|
3
|
+
attr_accessor :header, :data
|
4
|
+
# should add checks
|
5
|
+
# so taht every row is of the same size
|
6
|
+
|
7
|
+
def initialize header
|
8
|
+
@header = header
|
9
|
+
end
|
10
|
+
|
11
|
+
def printTable
|
12
|
+
# i should probably check for things
|
13
|
+
#if @data.empty?
|
14
|
+
# raise "Where is the data?"§
|
15
|
+
#end
|
16
|
+
sdata = [@header.clone]
|
17
|
+
sdata += self.datato_s
|
18
|
+
# does everything have to be turned into a string?
|
19
|
+
# i think so
|
20
|
+
|
21
|
+
# get longest item in a column
|
22
|
+
rpad = []
|
23
|
+
nrows = sdata[0].length
|
24
|
+
# the issue was, i was going for how many rows, should of gone by rows
|
25
|
+
# this is really confussing
|
26
|
+
# idk why it really works
|
27
|
+
0.upto(nrows -1).each do |i|
|
28
|
+
#p sdata[i]
|
29
|
+
rpad << sdata.max{|a, b| a[i].length <=> b[i].length}[i].length() +1
|
30
|
+
end
|
31
|
+
|
32
|
+
floor = '─'
|
33
|
+
wall = '│'
|
34
|
+
tsign = {:ut => '┴', :dt => '┬', :rt => '├', :lt => '┤', :cross => '┼'}
|
35
|
+
corner = {:tr => '┌', :tl => '┐', :br => '┘', :bl => '└'}
|
36
|
+
|
37
|
+
top = corner[:tr]
|
38
|
+
mid = tsign[:rt]
|
39
|
+
bot = corner[:bl]
|
40
|
+
|
41
|
+
head = "#{wall}"
|
42
|
+
(0...sdata[0].length).each do |i|
|
43
|
+
temp = " #{sdata[0][i].ljust(rpad[i])}#{wall}"
|
44
|
+
top += temp.split("").map{|s| floor}.join("")
|
45
|
+
top[-1] = tsign[:dt]
|
46
|
+
|
47
|
+
mid += temp.split("").map{|s| floor}.join("")
|
48
|
+
mid[-1] = tsign[:cross]
|
49
|
+
|
50
|
+
bot += temp.split("").map{|s| floor}.join("")
|
51
|
+
bot[-1] = tsign[:ut]
|
52
|
+
head << temp
|
53
|
+
end
|
54
|
+
top[-1] = corner[:tl]
|
55
|
+
mid[-1] = tsign[:lt]
|
56
|
+
bot[-1] = corner[:br]
|
57
|
+
|
58
|
+
puts top
|
59
|
+
puts head
|
60
|
+
puts mid
|
61
|
+
# we can start printing table
|
62
|
+
sdata[1..-1].each do |l|
|
63
|
+
(0...l.length()).each do |i|
|
64
|
+
print("#{wall} #{l[i].ljust(rpad[i])}")
|
65
|
+
end
|
66
|
+
print "#{wall}"
|
67
|
+
puts ""
|
68
|
+
end
|
69
|
+
|
70
|
+
puts bot
|
71
|
+
end
|
72
|
+
|
73
|
+
# is this a bad idea
|
74
|
+
# if there is alot of data?
|
75
|
+
private
|
76
|
+
def datato_s
|
77
|
+
stringify = []
|
78
|
+
@data.each do |row|
|
79
|
+
stringify << row.map {|e| e.to_s}
|
80
|
+
end
|
81
|
+
stringify
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cli-table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MrBocch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: jorgealberto1436@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cli-table.rb
|
20
|
+
homepage: https://github.com/MrBocch/cli-table
|
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
|
+
rubygems_version: 3.5.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Print 2d array into a pretty table
|
43
|
+
test_files: []
|