texttable 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/texttable.rb +19 -3
- data/texttable.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70f1463710df413ea94a0419ed453aefb94a2f4767acd24c9065a93445cccc2f
|
4
|
+
data.tar.gz: e3c2cf4d7a5713331d2645818b14fc840b163512acd0b602083ac013915aa358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1699e9ce322a6ffc8944873436c536f9a7335f52f6b4f74181681fccba746102fdabca97367bd1d20fc4713f5614e5af15d38d00a94e1593f44591877d7f2821
|
7
|
+
data.tar.gz: e220b3a863cbe0abb3396afa4623f28838e6fe534c1245ef70df5ff888ceb5f6aaf6d095821db83c9d8a154d42be5300a83f7b244861f3c050d36e7adf781589
|
data/lib/texttable.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class TextTable
|
2
2
|
attr_accessor :values, :rows
|
3
3
|
|
4
|
-
def initialize(cols=nil)
|
4
|
+
def initialize(cols=nil, rows=nil)
|
5
5
|
@cols = Hash.new {|h,k| h[k] = h.size}
|
6
|
-
@rows = []
|
6
|
+
@rows = rows || []
|
7
7
|
@values = nil
|
8
8
|
@row = 0
|
9
9
|
cols.each {|col| index!(col) } if cols.is_a?(Array)
|
@@ -12,7 +12,7 @@ class TextTable
|
|
12
12
|
def index(field, auto=false)
|
13
13
|
case field
|
14
14
|
when String, Symbol
|
15
|
-
field = field
|
15
|
+
field = convert_key(field)
|
16
16
|
index = @cols.key?(field) ? @cols[field] : auto ? @cols[field] : nil
|
17
17
|
when Numeric
|
18
18
|
field
|
@@ -25,6 +25,16 @@ class TextTable
|
|
25
25
|
index(field, true)
|
26
26
|
end
|
27
27
|
|
28
|
+
def convert_key(key)
|
29
|
+
key.to_s.gsub(/\W/, '_').gsub(/(.)([A-Z])/, '\1_\2').downcase # allow CamelCase
|
30
|
+
# key.to_s.gsub(/\W/, '_').downcase # allow non-word chars
|
31
|
+
# key.to_s.downcase # force downcase
|
32
|
+
end
|
33
|
+
|
34
|
+
def size
|
35
|
+
@rows.size
|
36
|
+
end
|
37
|
+
|
28
38
|
def fields
|
29
39
|
@cols.keys
|
30
40
|
end
|
@@ -120,3 +130,9 @@ class TextTable
|
|
120
130
|
end
|
121
131
|
end
|
122
132
|
end
|
133
|
+
|
134
|
+
class ActiveRecord::Result
|
135
|
+
def +@
|
136
|
+
TextTable.new(columns, rows)
|
137
|
+
end
|
138
|
+
end
|
data/texttable.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem will auto-size based on column widths.
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -41,8 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
|
-
|
45
|
-
rubygems_version: 2.7.7
|
44
|
+
rubygems_version: 3.0.6
|
46
45
|
signing_key:
|
47
46
|
specification_version: 4
|
48
47
|
summary: An easy way to print rows and columns as simple tables
|