texttable 0.9.0 → 1.0.0

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 +19 -3
  3. data/texttable.gemspec +1 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca77eab48d17c39307bd1f4b58b31ba497d63c008628e765b026153870ee8397
4
- data.tar.gz: 953d2d5b6cea2e116085d8b7df57b7542382cd3b24db31cc8e5d219d500da220
3
+ metadata.gz: 70f1463710df413ea94a0419ed453aefb94a2f4767acd24c9065a93445cccc2f
4
+ data.tar.gz: e3c2cf4d7a5713331d2645818b14fc840b163512acd0b602083ac013915aa358
5
5
  SHA512:
6
- metadata.gz: d70caf947e3da7c9e0fa397c640a3440f971a632626ae7b3af77023fa0c0ac75148483d1b07302fbb9d3d83656b56ff9f094cbb430ad2a800e4d1ff075375cba
7
- data.tar.gz: 6452e896deb0406ab93e3284462f90fcd72abd0c294d5067b0880ebb457a54fe5bad0eed63dbc9f556a3a13ca805a9252dfdda059816db5f117c009f0ab0c097
6
+ metadata.gz: 1699e9ce322a6ffc8944873436c536f9a7335f52f6b4f74181681fccba746102fdabca97367bd1d20fc4713f5614e5af15d38d00a94e1593f44591877d7f2821
7
+ data.tar.gz: e220b3a863cbe0abb3396afa4623f28838e6fe534c1245ef70df5ff888ceb5f6aaf6d095821db83c9d8a154d42be5300a83f7b244861f3c050d36e7adf781589
@@ -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.to_s
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "texttable"
5
- s.version = "0.9.0"
5
+ s.version = "1.0.0"
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: 0.9.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-08 00:00:00.000000000 Z
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
- rubyforge_project:
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