cellar 0.1.5 → 0.1.6

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/cellar.rb +34 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be9c519146063e4b17e8736dfd6d58f968411ef172c2c7ba4bb6f9f2669f7ebc
4
- data.tar.gz: a030af0aaa876017a8ec86960aff3fb3f10d0265b8750b6a7f2fb8e14260f5ce
3
+ metadata.gz: ac9fdc01c855bbb6e9bfb1039562518f2296004f705dd93eb57c3cc8a659c2b7
4
+ data.tar.gz: 46b151aee44708d5845ed6e2cf37813666352d2bf55cbb1ac8f73918758a0f94
5
5
  SHA512:
6
- metadata.gz: 2d6004af8953418d4b3e76cc96fd7ed3e7f6b26cef82f11eb0b5f2476aef4249b63dad569eecfeb31618115606b204ce41fdb58b6b4187ef1521a2b89007321c
7
- data.tar.gz: a1b75505baec7086b318b2d88f5bea5a2bb80aa0aec53373a065f545867e72b7f3551bde3a841cfc47941142474da932753b9343a95219655583cd21e5e70d31
6
+ metadata.gz: 974c75e352a63d10709d228cb1aab85b26756702d2df643ed95b7767134b6c9c39c3f67e5ee40ccd09d98745d6eee71330a0e1ed3cf3fa71235b46223eb26dba
7
+ data.tar.gz: 68a1494d0fc10db818c3a78e7e570901fe0b96b0a5e0b8264fae26afcf2308523a6570473d48903cf3c25bdef0c260c330f42819e7741d1c74086f4b6ff9f438
data/lib/cellar.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # cellar - Ruby gem to deal with cells of data in rows and columns
3
3
  #
4
4
  # Author: Steve Shreeve (steve.shreeve@gmail.com)
5
- # Date: October 9, 2024
5
+ # Date: October 14, 2024
6
6
  #
7
7
  # TODO:
8
8
  # • Should we failover to empty strings like this: (value || "")
@@ -24,7 +24,7 @@ class Object
24
24
  end
25
25
 
26
26
  class Cellar
27
- VERSION="0.1.5"
27
+ VERSION="0.1.6"
28
28
 
29
29
  attr_reader :fields
30
30
  attr_reader :values
@@ -211,7 +211,7 @@ class Cellar
211
211
  @rows << @values = []
212
212
  self[*data.fields] = data.values
213
213
  elsif data.is_a?(Array) && !data.first.is_a?(Array)
214
- @rows << data
214
+ @rows << (@values = data)
215
215
  else
216
216
  raise "unable to << your object"
217
217
  end
@@ -282,4 +282,35 @@ class Cellar
282
282
  h
283
283
  end
284
284
  end
285
+
286
+ # ==[ Show table ]==
287
+
288
+ def show?
289
+ self
290
+ end
291
+
292
+ def show!(list=nil, output: :stdout)
293
+ tabs = output == :tabs
294
+ meth = list.is_a?(Array) ? list.method(:push) : method(:puts)
295
+ join = tabs ? "\t" : " │ "
296
+ size = @fields.size
297
+ full = cells
298
+ full.each_with_index do |vals, i| # only when asymmetric
299
+ miss = size - vals.size
300
+ full[i] += [nil] * miss if miss > 0
301
+ full[i] = vals[0...size] if miss < 0
302
+ end
303
+ lens = full.map {|r| r.map {|c| c.to_s.size}}.transpose.map(&:max)
304
+ pict = lens.map {|len| "%-#{len}.#{len}s" }.join(join)
305
+ pict = [join, pict, join].join.strip
306
+ line = (pict % ([""] * size)).tr("│ ", "•─")
307
+ seen = -1
308
+ meth["", line] unless tabs
309
+ full.each do |vals|
310
+ meth[pict % vals]
311
+ meth[line] if !tabs && ((seen += 1) == 0)
312
+ end
313
+ meth[line, "#{seen} rows displayed", ""] unless tabs
314
+ self
315
+ end
285
316
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cellar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-10 00:00:00.000000000 Z
11
+ date: 2024-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem to deal with cells of data in rows and columns
14
14
  email: steve.shreeve@gmail.com