cli-table 0.0.1 → 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 +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28051eeb3d368afcf40bd6c7e54b3e7edbfd12230d77b4ca119ca70a9058df3b
4
- data.tar.gz: 9315767f4120937775524b254c9b16e13d8dc531eac5ae942cda74c0ec89c6a0
3
+ metadata.gz: f3b277e92cc37f85b404e0853561d0ca5a3237012962d51fba55ed9e3316af9f
4
+ data.tar.gz: a75938af780d98b390b0d22f92fa3881aaa519b9b15a6b2011aaa64714b7f245
5
5
  SHA512:
6
- metadata.gz: 6ef1c65fa870f8d4fd19a7aeea13316f197b4cda652de6ee6e2a94690a8381a673be7394faea9f8bd4cabbe85414db973f305c9617e8772ed3411d8e38c48803
7
- data.tar.gz: 957893c6046bdf9824cc54991f6b4d1c7e58c551f62406a9df480b7dc97d093e627157abfc682ff3233d24485ba6807b0ced68377e19f6d5eb1eb9bcc8c12b9a
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.1
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
@@ -39,5 +39,5 @@ requirements: []
39
39
  rubygems_version: 3.5.3
40
40
  signing_key:
41
41
  specification_version: 4
42
- summary: Print 2d array into a pretty table
42
+ summary: Print 2d array into a pretty table. https://github.com/MrBocch/cli-table
43
43
  test_files: []