texttable 1.0.3 → 1.0.4

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 +17 -7
  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: b58302bced8b39ec31855f2df2955806ac3f3e1f5849cc2607ce5becc47192d2
4
- data.tar.gz: 664bce812373db1aa8dfcf8ff42acf5a04f65499f139481b16049c020ee791ba
3
+ metadata.gz: 3c035cbbcd41305294dd4118ac345509de89a5705d40c4051cc3e788ea208a5e
4
+ data.tar.gz: 6af6f4624fc36ff624a9f98d19919e177bef5686b87c139d360a7f84c6514451
5
5
  SHA512:
6
- metadata.gz: 5e917ab55e896348e501e73e86169d2f39a23edf1cc4aba8b107a1bf937d4fa95ff5dbe220c14bf12a10ab9f08fb9931f3def7ae590a8fe4204a740513f53576
7
- data.tar.gz: e88702ff63feb31661190a5294fa9ee7ce9a93044228684897d8ffa56ae1614f54b8c842a415df2efc85e981b846aa16abb0f4b818614260005c9f8e63653408
6
+ metadata.gz: 9ed008e7c217c7c7ae9b90b5f2ff1716816a25240c35279a5aea92e92b96414eb75274ffb28efa8afd9815f57fa487d0d6c57484f1d03f4c366801c44ba9e515
7
+ data.tar.gz: 4a618de33a78ab41386f5ac8ec7f4f68781c8601b83ef694d9f55644a6e2089bfce821f67570036354b101f0d1b3448f6341380d28bb032e52ab3824da1c7a03
data/lib/texttable.rb CHANGED
@@ -1,12 +1,19 @@
1
1
  class TextTable
2
2
  attr_accessor :values, :rows
3
3
 
4
- def initialize(cols=nil, rows=nil)
4
+ def initialize(*args)
5
+ if args[0].is_a?(Array)
6
+ cols, *rows = args
7
+ rows = rows[0] if rows[0].is_a?(Array)
8
+ else
9
+ cols = args
10
+ rows = []
11
+ end
5
12
  @cols = Hash.new {|h,k| h[k] = h.size}
6
- @rows = rows || []
13
+ @rows = rows
7
14
  @values = nil
8
15
  @row = 0
9
- cols.each {|col| index!(col) } if cols.is_a?(Array)
16
+ cols.each {|col| index!(col) }
10
17
  end
11
18
 
12
19
  def index(field, auto=false)
@@ -26,9 +33,11 @@ class TextTable
26
33
  end
27
34
 
28
35
  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
36
+ key.
37
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
38
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
39
+ gsub(/\W/, '_').
40
+ downcase
32
41
  end
33
42
 
34
43
  def size
@@ -83,7 +92,8 @@ class TextTable
83
92
  value
84
93
  end
85
94
 
86
- def add(obj)
95
+ def add(obj, *args)
96
+ obj = [obj, *args] if args.size > 0
87
97
  @values = @rows[@row = @rows.size] = []
88
98
  case obj
89
99
  when Hash then obj.each {|k, v| @values[@cols[k]] = v}
data/texttable.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "texttable"
5
- s.version = "1.0.3"
5
+ s.version = "1.0.4"
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.3
4
+ version: 1.0.4
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-14 00:00:00.000000000 Z
11
+ date: 2019-11-16 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