texttable 1.0.2 → 1.0.3
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 +14 -6
- data/texttable.gemspec +1 -1
- 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: b58302bced8b39ec31855f2df2955806ac3f3e1f5849cc2607ce5becc47192d2
|
4
|
+
data.tar.gz: 664bce812373db1aa8dfcf8ff42acf5a04f65499f139481b16049c020ee791ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e917ab55e896348e501e73e86169d2f39a23edf1cc4aba8b107a1bf937d4fa95ff5dbe220c14bf12a10ab9f08fb9931f3def7ae590a8fe4204a740513f53576
|
7
|
+
data.tar.gz: e88702ff63feb31661190a5294fa9ee7ce9a93044228684897d8ffa56ae1614f54b8c842a415df2efc85e981b846aa16abb0f4b818614260005c9f8e63653408
|
data/lib/texttable.rb
CHANGED
@@ -83,9 +83,14 @@ class TextTable
|
|
83
83
|
value
|
84
84
|
end
|
85
85
|
|
86
|
-
def add(
|
86
|
+
def add(obj)
|
87
87
|
@values = @rows[@row = @rows.size] = []
|
88
|
-
|
88
|
+
case obj
|
89
|
+
when Hash then obj.each {|k, v| @values[@cols[k]] = v}
|
90
|
+
when Array then @values.replace(obj)
|
91
|
+
else raise "unable to add #{obj.class} objects"
|
92
|
+
end
|
93
|
+
self
|
89
94
|
end
|
90
95
|
|
91
96
|
def show
|
@@ -112,22 +117,25 @@ class TextTable
|
|
112
117
|
csv[:encoding] = encoding + ":UTF-8" if encoding
|
113
118
|
csv[:col_sep ] = sep
|
114
119
|
csv = CSV.new($stdout, csv)
|
115
|
-
csv << cols.keys
|
116
|
-
rows.each {|vals| csv << vals}
|
120
|
+
csv << @cols.keys
|
121
|
+
@rows.each {|vals| csv << vals}
|
122
|
+
nil
|
117
123
|
end
|
118
124
|
def tsv; csv("\t"); end
|
119
125
|
def psv; csv("|" ); end
|
120
126
|
|
121
127
|
def sql(table='table', quote: false)
|
122
128
|
q = quote ? '`' : ''
|
123
|
-
flip = cols.invert
|
124
|
-
rows.each do |vals|
|
129
|
+
flip = @cols.invert
|
130
|
+
@rows.each do |vals|
|
125
131
|
list = vals.each_with_index.inject([]) do |list, (item, i)|
|
132
|
+
item = item.to_s #!# FIXME: force all to a string for now...
|
126
133
|
list << "#{q}#{flip[i]}#{q}='#{item.gsub("'","''")}'" if item =~ /\S/
|
127
134
|
list
|
128
135
|
end
|
129
136
|
puts "insert into #{q}#{table}#{q} set #{list * ', '};" if !list.empty?
|
130
137
|
end
|
138
|
+
nil
|
131
139
|
end
|
132
140
|
end
|
133
141
|
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
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-11-
|
11
|
+
date: 2019-11-14 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
|