cli-table 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli-table.rb +21 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7136b5f1506c0c36979fb9ec6a01de52169f379061e150b7834a8cc9ea683d8
4
- data.tar.gz: 32fc389d827872f96491e1417cf00466bcbed6126e567b778f37e1c1e7040bde
3
+ metadata.gz: f3b277e92cc37f85b404e0853561d0ca5a3237012962d51fba55ed9e3316af9f
4
+ data.tar.gz: a75938af780d98b390b0d22f92fa3881aaa519b9b15a6b2011aaa64714b7f245
5
5
  SHA512:
6
- metadata.gz: c6c415e50a2a30377963acf7860c03872d6b755ab11348545f58839ade2a874b54813c5b62789de47afe7ec8b5ca7590570b3fc941b902da7f1313eca40f0f27
7
- data.tar.gz: 413b4d43f2bd1e5a348657bc4c9dea1c8cf986d52f52bd525d2b1fb0b7db642a79f3f9011087c7bc7c394b45e81938fd6905b9f8382cae0e61a98866a1d3945b
6
+ metadata.gz: 0c04ffda91a043fed2255b5710e62ce8b1ca947bf021614a45e5b055220a9f640add3072157c9a979c4bfeb810006523aa6f95b204237083ab37eda7796e7840
7
+ data.tar.gz: 2e187797c1651f5fc3908a972a1eba2e57d7614a96ab88059eca0bbdbe693243e546a075d8f77e94aa29f7193e6fe54494d8887b1e489e2f4004d3244d923e75
data/lib/cli-table.rb CHANGED
@@ -1,36 +1,37 @@
1
1
 
2
2
  class Table
3
- attr_accessor :header, :data
3
+ attr_accessor :header, :rows
4
4
  # should add checks
5
- # so taht every row is of the same size
5
+ # so taht every row is of the same size
6
6
 
7
- def initialize header
7
+ def initialize header
8
8
  @header = header
9
+ @rows = []
9
10
  end
10
11
 
11
- def printTable
12
- # i should probably check for things
13
- #if @data.empty?
14
- # raise "Where is the data?"§
12
+ def show
13
+ # i should probably check for things
14
+ #if @rows.empty?
15
+ # raise "Where is the rows?"§
15
16
  #end
16
17
  sdata = [@header.clone]
17
18
  sdata += self.datato_s
18
19
  # does everything have to be turned into a string?
19
- # i think so
20
+ # i think so
20
21
 
21
22
  # get longest item in a column
22
23
  rpad = []
23
24
  nrows = sdata[0].length
24
25
  # the issue was, i was going for how many rows, should of gone by rows
25
26
  # this is really confussing
26
- # idk why it really works
27
+ # idk why it really works
27
28
  0.upto(nrows -1).each do |i|
28
29
  #p sdata[i]
29
30
  rpad << sdata.max{|a, b| a[i].length <=> b[i].length}[i].length() +1
30
31
  end
31
-
32
+
32
33
  floor = '─'
33
- wall = '│'
34
+ wall = '│'
34
35
  tsign = {:ut => '┴', :dt => '┬', :rt => '├', :lt => '┤', :cross => '┼'}
35
36
  corner = {:tr => '┌', :tl => '┐', :br => '┘', :bl => '└'}
36
37
 
@@ -55,10 +56,10 @@ class Table
55
56
  mid[-1] = tsign[:lt]
56
57
  bot[-1] = corner[:br]
57
58
 
58
- puts top
59
+ puts top
59
60
  puts head
60
61
  puts mid
61
- # we can start printing table
62
+ # we can start printing table
62
63
  sdata[1..-1].each do |l|
63
64
  (0...l.length()).each do |i|
64
65
  print("#{wall} #{l[i].ljust(rpad[i])}")
@@ -67,7 +68,7 @@ class Table
67
68
  puts ""
68
69
  end
69
70
 
70
- puts bot
71
+ puts bot
71
72
  end
72
73
 
73
74
  # is this a bad idea
@@ -75,9 +76,12 @@ class Table
75
76
  private
76
77
  def datato_s
77
78
  stringify = []
78
- @data.each do |row|
79
- stringify << row.map {|e| e.to_s}
79
+ if not rows.empty?
80
+ @rows.each do |row|
81
+ stringify << row.map {|e| e.to_s}
82
+ end
80
83
  end
84
+
81
85
  stringify
82
86
  end
83
- end
87
+ 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.2
4
+ version: 0.1.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-02-23 00:00:00.000000000 Z
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: jorgealberto1436@gmail.com