cli-table 0.0.2 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/cli-table.rb +64 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60742061164fe7686dd85069641fd07c57514e334754e9a39bdd363150a2d1ae
|
4
|
+
data.tar.gz: 147435164b77220c90e8b33c2e2f1dbfa36cc6cd67652d8ca197eea543ca8254
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 715083c77e5bf95143a8c5128b2b6935b05f2740288794eedcf70bb4bbf1dffe882d48eec7668a86488556fc4ea75089519a90a2ea20c29f4fc67d972ffafbd2
|
7
|
+
data.tar.gz: 486ea55cca001ee5dba98c5f164aa59a655f31b43d3794f7642ae59cbf3d700b55b057aa97a2b46d71fb41f5f4392afc5bbc762e0b1fdbe99098bf425e8e0cc5
|
data/lib/cli-table.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
|
2
2
|
class Table
|
3
|
-
attr_accessor :header, :
|
4
|
-
# should add checks
|
5
|
-
# so taht every row is of the same size
|
3
|
+
attr_accessor :header, :rows
|
6
4
|
|
7
|
-
def initialize header
|
5
|
+
def initialize header
|
8
6
|
@header = header
|
7
|
+
@rows = []
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
10
|
+
def show
|
11
|
+
|
12
|
+
# wish i could explain what line of code its wrong
|
13
|
+
if not is_correct then return end
|
14
|
+
|
16
15
|
sdata = [@header.clone]
|
17
16
|
sdata += self.datato_s
|
18
17
|
# does everything have to be turned into a string?
|
19
|
-
# i think so
|
18
|
+
# i think so
|
20
19
|
|
21
20
|
# get longest item in a column
|
22
21
|
rpad = []
|
23
22
|
nrows = sdata[0].length
|
24
23
|
# the issue was, i was going for how many rows, should of gone by rows
|
25
24
|
# this is really confussing
|
26
|
-
# idk why it really works
|
25
|
+
# idk why it really works
|
27
26
|
0.upto(nrows -1).each do |i|
|
28
27
|
#p sdata[i]
|
29
28
|
rpad << sdata.max{|a, b| a[i].length <=> b[i].length}[i].length() +1
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
floor = '─'
|
33
|
-
wall = '│'
|
32
|
+
wall = '│'
|
34
33
|
tsign = {:ut => '┴', :dt => '┬', :rt => '├', :lt => '┤', :cross => '┼'}
|
35
34
|
corner = {:tr => '┌', :tl => '┐', :br => '┘', :bl => '└'}
|
36
35
|
|
@@ -55,10 +54,10 @@ class Table
|
|
55
54
|
mid[-1] = tsign[:lt]
|
56
55
|
bot[-1] = corner[:br]
|
57
56
|
|
58
|
-
puts top
|
57
|
+
puts top
|
59
58
|
puts head
|
60
59
|
puts mid
|
61
|
-
# we can start printing table
|
60
|
+
# we can start printing table
|
62
61
|
sdata[1..-1].each do |l|
|
63
62
|
(0...l.length()).each do |i|
|
64
63
|
print("#{wall} #{l[i].ljust(rpad[i])}")
|
@@ -67,7 +66,24 @@ class Table
|
|
67
66
|
puts ""
|
68
67
|
end
|
69
68
|
|
70
|
-
puts bot
|
69
|
+
puts bot
|
70
|
+
end
|
71
|
+
|
72
|
+
def is_correct?
|
73
|
+
if @rows == []
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
|
77
|
+
t = @rows.map {|l| l.length}.uniq
|
78
|
+
if t.length != 1
|
79
|
+
return false
|
80
|
+
end
|
81
|
+
|
82
|
+
if t[0] != @header.length
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
return true
|
71
87
|
end
|
72
88
|
|
73
89
|
# is this a bad idea
|
@@ -75,9 +91,38 @@ class Table
|
|
75
91
|
private
|
76
92
|
def datato_s
|
77
93
|
stringify = []
|
78
|
-
|
79
|
-
|
94
|
+
if not rows.empty?
|
95
|
+
@rows.each do |row|
|
96
|
+
stringify << row.map {|e| e.to_s}
|
97
|
+
end
|
80
98
|
end
|
99
|
+
|
81
100
|
stringify
|
82
101
|
end
|
83
|
-
|
102
|
+
private
|
103
|
+
def explain_error why
|
104
|
+
puts "\n [cli-table]: #{why}"
|
105
|
+
end
|
106
|
+
private
|
107
|
+
def is_correct
|
108
|
+
|
109
|
+
if @rows == []
|
110
|
+
return true
|
111
|
+
end
|
112
|
+
|
113
|
+
t = @rows.map {|l| l.length}.uniq
|
114
|
+
if t.length != 1
|
115
|
+
explain_error "Cant print table because rows are different size"
|
116
|
+
puts caller[1..2]
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
if t[0] != @header.length
|
121
|
+
explain_error "Cant print because rows size is different from header size"
|
122
|
+
puts caller[1..2]
|
123
|
+
return false
|
124
|
+
end
|
125
|
+
|
126
|
+
return true
|
127
|
+
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MrBocch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: jorgealberto1436@gmail.com
|