cli-table 0.1.0 → 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli-table.rb +47 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3b277e92cc37f85b404e0853561d0ca5a3237012962d51fba55ed9e3316af9f
4
- data.tar.gz: a75938af780d98b390b0d22f92fa3881aaa519b9b15a6b2011aaa64714b7f245
3
+ metadata.gz: 60742061164fe7686dd85069641fd07c57514e334754e9a39bdd363150a2d1ae
4
+ data.tar.gz: 147435164b77220c90e8b33c2e2f1dbfa36cc6cd67652d8ca197eea543ca8254
5
5
  SHA512:
6
- metadata.gz: 0c04ffda91a043fed2255b5710e62ce8b1ca947bf021614a45e5b055220a9f640add3072157c9a979c4bfeb810006523aa6f95b204237083ab37eda7796e7840
7
- data.tar.gz: 2e187797c1651f5fc3908a972a1eba2e57d7614a96ab88059eca0bbdbe693243e546a075d8f77e94aa29f7193e6fe54494d8887b1e489e2f4004d3244d923e75
6
+ metadata.gz: 715083c77e5bf95143a8c5128b2b6935b05f2740288794eedcf70bb4bbf1dffe882d48eec7668a86488556fc4ea75089519a90a2ea20c29f4fc67d972ffafbd2
7
+ data.tar.gz: 486ea55cca001ee5dba98c5f164aa59a655f31b43d3794f7642ae59cbf3d700b55b057aa97a2b46d71fb41f5f4392afc5bbc762e0b1fdbe99098bf425e8e0cc5
data/lib/cli-table.rb CHANGED
@@ -1,8 +1,6 @@
1
1
 
2
2
  class Table
3
3
  attr_accessor :header, :rows
4
- # should add checks
5
- # so taht every row is of the same size
6
4
 
7
5
  def initialize header
8
6
  @header = header
@@ -10,10 +8,10 @@ class Table
10
8
  end
11
9
 
12
10
  def show
13
- # i should probably check for things
14
- #if @rows.empty?
15
- # raise "Where is the rows?"§
16
- #end
11
+
12
+ # wish i could explain what line of code its wrong
13
+ if not is_correct then return end
14
+
17
15
  sdata = [@header.clone]
18
16
  sdata += self.datato_s
19
17
  # does everything have to be turned into a string?
@@ -71,6 +69,23 @@ class Table
71
69
  puts bot
72
70
  end
73
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
87
+ end
88
+
74
89
  # is this a bad idea
75
90
  # if there is alot of data?
76
91
  private
@@ -84,4 +99,30 @@ class Table
84
99
 
85
100
  stringify
86
101
  end
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
87
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.1.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-08-29 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: jorgealberto1436@gmail.com