texttable 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/texttable.rb +14 -6
  3. data/texttable.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc235765c111324bc8acf802e9db55ce82b787ba696d6777151c7c92754e0d2
4
- data.tar.gz: 7319fc51ee82db342addb5f6fa0086ae4498031a3cdf6ed9fb3a9b50776dfd6a
3
+ metadata.gz: b58302bced8b39ec31855f2df2955806ac3f3e1f5849cc2607ce5becc47192d2
4
+ data.tar.gz: 664bce812373db1aa8dfcf8ff42acf5a04f65499f139481b16049c020ee791ba
5
5
  SHA512:
6
- metadata.gz: 83b0233c215082196e62d06c0332c7e730090d09e6aad274a184fa6f108af4cead8b5afaddf5196f7f082cc4265dfdbdd50c4985a8702bc0a6fa198743730daf
7
- data.tar.gz: 61edc55c5e93bf8797495e57d3946d5b28bc4de915558da778373e903eafd7021bc1f4514e07c15a0a07f041698d3ec10be4375d01998d0bc7bfe53e7937fd9b
6
+ metadata.gz: 5e917ab55e896348e501e73e86169d2f39a23edf1cc4aba8b107a1bf937d4fa95ff5dbe220c14bf12a10ab9f08fb9931f3def7ae590a8fe4204a740513f53576
7
+ data.tar.gz: e88702ff63feb31661190a5294fa9ee7ce9a93044228684897d8ffa56ae1614f54b8c842a415df2efc85e981b846aa16abb0f4b818614260005c9f8e63653408
@@ -83,9 +83,14 @@ class TextTable
83
83
  value
84
84
  end
85
85
 
86
- def add(hash)
86
+ def add(obj)
87
87
  @values = @rows[@row = @rows.size] = []
88
- hash.each {|k, v| @values[@cols[k]] = v}
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "texttable"
5
- s.version = "1.0.2"
5
+ s.version = "1.0.3"
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary = "An easy way to print rows and columns as simple tables"
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.2
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-02 00:00:00.000000000 Z
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