texttable 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/lib/texttable.rb +31 -0
- data/texttable.gemspec +13 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d414e056753b18aad741029e85f39f38dba232d97a38e03ba10407a835923b
|
4
|
+
data.tar.gz: 69c37ea0dc86881c438956035ddad85f5f17dc3f940e7e0e5ba42f072eae6593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d524d290960e9c9e573599249898ce0dfffbcfffa2b30f4cb77fc11d50cf1889a4c061fdb8b957b8144e9f9578857e47e1046b564e5d729c4218b9b8b1f63352
|
7
|
+
data.tar.gz: c0a06bc70df55c76b11bdb9dde04699cd41b395c7ccae4cf50512d957fa0329517eb49af1486aa43ad93935d25551eb01751220621b57db4309513667052b985
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5
|
data/Gemfile
ADDED
data/lib/texttable.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class TextTable
|
2
|
+
attr_accessor :cols, :rows
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@cols = Hash.new{|h,k| h[k] = h.size}
|
6
|
+
@rows = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(hash)
|
10
|
+
@rows << (vals = [])
|
11
|
+
hash.each {|k, v| vals[@cols[k]] = v}
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
join = " | "
|
16
|
+
both = [cols.keys] + rows
|
17
|
+
flip = both.transpose
|
18
|
+
wide = flip.map {|row| row.map {|col| col.to_s.size }.max }
|
19
|
+
pict = wide.map {|len| "%-#{len}.#{len}s" }.join(join)
|
20
|
+
pict = [join, pict, join].join.strip
|
21
|
+
line = (pict % ([""] * cols.size)).tr("| ", "+-")
|
22
|
+
seen = -1
|
23
|
+
puts "", line
|
24
|
+
both.each do |vals|
|
25
|
+
puts pict % vals
|
26
|
+
puts line if (seen += 1) == 0
|
27
|
+
end
|
28
|
+
puts line, "#{seen} rows displayed", ""
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
data/texttable.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "texttable"
|
5
|
+
s.version = "0.6.0"
|
6
|
+
s.author = "Steve Shreeve"
|
7
|
+
s.email = "steve.shreeve@gmail.com"
|
8
|
+
s.summary = "An easy way to print rows and columns as simple tables"
|
9
|
+
s.description = "This gem will auto-size based on column widths."
|
10
|
+
s.homepage = "https://github.com/shreeve/texttable"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
@@ -16,8 +16,12 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- ".ruby-version"
|
20
|
+
- Gemfile
|
19
21
|
- LICENSE
|
20
22
|
- README.md
|
23
|
+
- lib/texttable.rb
|
24
|
+
- texttable.gemspec
|
21
25
|
homepage: https://github.com/shreeve/texttable
|
22
26
|
licenses:
|
23
27
|
- MIT
|