cellar 0.1.4 → 0.1.6
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/cellar.rb +47 -3
- 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: ac9fdc01c855bbb6e9bfb1039562518f2296004f705dd93eb57c3cc8a659c2b7
|
4
|
+
data.tar.gz: 46b151aee44708d5845ed6e2cf37813666352d2bf55cbb1ac8f73918758a0f94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
27
|
+
VERSION="0.1.6"
|
28
28
|
|
29
29
|
attr_reader :fields
|
30
30
|
attr_reader :values
|
@@ -62,6 +62,19 @@ class Cellar
|
|
62
62
|
index
|
63
63
|
end
|
64
64
|
|
65
|
+
def rename_field(field, other)
|
66
|
+
field = field.to_s
|
67
|
+
index = index(field) or raise "unable to rename the #{field.inspect} field"
|
68
|
+
@finder.delete(field.downcase.gsub(/\W/,'_'))
|
69
|
+
@finder.delete(field)
|
70
|
+
other = other.to_s
|
71
|
+
fields[index] = other
|
72
|
+
@finder[other.downcase.gsub(/\W/,'_')] ||= index
|
73
|
+
@finder[other] ||= index
|
74
|
+
@widest = fields.map(&:size).max
|
75
|
+
index
|
76
|
+
end
|
77
|
+
|
65
78
|
def index(field)
|
66
79
|
case field
|
67
80
|
when String, Symbol
|
@@ -198,7 +211,7 @@ class Cellar
|
|
198
211
|
@rows << @values = []
|
199
212
|
self[*data.fields] = data.values
|
200
213
|
elsif data.is_a?(Array) && !data.first.is_a?(Array)
|
201
|
-
@rows << data
|
214
|
+
@rows << (@values = data)
|
202
215
|
else
|
203
216
|
raise "unable to << your object"
|
204
217
|
end
|
@@ -269,4 +282,35 @@ class Cellar
|
|
269
282
|
h
|
270
283
|
end
|
271
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
|
272
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.
|
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-
|
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
|