texttable 1.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -2
- data/lib/texttable.rb +17 -7
- data/texttable.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dc849d43312afb4106b6db6908f154f937409c3ac780a6d2ee36645f7155e7d
|
4
|
+
data.tar.gz: d947accbe4d63f66d6c9d321aa96f8936a594d4c5a3e34dd05259b61645bb3c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b40935ce7e9ea135221c2505cb6ea7c597d67f5d9e991b834c801ef7eb3fd162e1d320b2eec1c3b835bc343d4f8d5c5f5afebf7ba2b7e28164c69d16166b97d3
|
7
|
+
data.tar.gz: 1e21bbc4c2ebf4439910113ee6d0136c36894f2c7d2e357a82163e3e69842f051ea9903be5bed95cafc15a0a226a0f379655ba0df631b4301cdd5ddbaf3f3cf4
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# texttable
|
2
2
|
|
3
|
-
`texttable` is a Ruby gem that provides an easy way to
|
3
|
+
`texttable` is a Ruby gem that provides an easy way to ingest, manage, and output rows and columns as simple tables.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Simple Example
|
6
6
|
|
7
7
|
This code:
|
8
8
|
|
@@ -30,3 +30,34 @@ Will produce:
|
|
30
30
|
+-------+-----+--------------+
|
31
31
|
4 rows displayed
|
32
32
|
```
|
33
|
+
|
34
|
+
## Loading Example
|
35
|
+
|
36
|
+
This code:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require "texttable"
|
40
|
+
|
41
|
+
info = TextTable.csv("data.csv")
|
42
|
+
info.show!
|
43
|
+
```
|
44
|
+
|
45
|
+
With the file `data.csv`:
|
46
|
+
|
47
|
+
```csv
|
48
|
+
id,first_name,last_name,email,cell,dept,photo,status
|
49
|
+
28,Mark,Jones,mark@bigcompany.com,800-555-1000,Finance,mark-jones.jpg,2
|
50
|
+
29,Sally,Miller,sally@bigcompany.com,800-555-2000,Accounting,sally-miller.jpg,1
|
51
|
+
```
|
52
|
+
|
53
|
+
Will produce:
|
54
|
+
|
55
|
+
```text
|
56
|
+
+----+------------+-----------+----------------------+--------------+------------+------------------+--------+
|
57
|
+
| id | first_name | last_name | email | cell | dept | photo | status |
|
58
|
+
+----+------------+-----------+----------------------+--------------+------------+------------------+--------+
|
59
|
+
| 28 | Mark | Jones | mark@bigcompany.com | 800-555-1000 | Finance | mark-jones.jpg | 2 |
|
60
|
+
| 29 | Sally | Miller | sally@bigcompany.com | 800-555-2000 | Accounting | sally-miller.jpg | 1 |
|
61
|
+
+----+------------+-----------+----------------------+--------------+------------+------------------+--------+
|
62
|
+
2 rows displayed
|
63
|
+
```
|
data/lib/texttable.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
class TextTable
|
2
2
|
attr_accessor :values, :rows
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class << self
|
5
|
+
def csv(src, sep=',', encoding: nil)
|
6
|
+
require 'csv'
|
7
|
+
new CSV.read(src || ARGF, {
|
8
|
+
col_sep: sep,
|
9
|
+
encoding: encoding ? encoding + ":UTF-8" : nil,
|
10
|
+
}.compact)
|
11
11
|
end
|
12
|
+
def tsv(*args); csv(args.shift, "\t", *args); end
|
13
|
+
def psv(*args); csv(args.shift, "|" , *args); end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(*args)
|
17
|
+
cols = args
|
18
|
+
cols = cols[0] if cols[0].is_a?(Array) && cols[0][0].is_a?(Array)
|
19
|
+
cols, *rows = cols if cols[0].is_a?(Array)
|
20
|
+
rows = *rows[0] if rows && rows[0].is_a?(Array) && rows[0][0].is_a?(Array)
|
21
|
+
rows = [] if !rows || !rows[0].is_a?(Array)
|
12
22
|
@cols = Hash.new {|h,k| h[k] = h.size}
|
13
23
|
@rows = rows
|
14
24
|
@values = nil
|
data/texttable.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "texttable"
|
5
|
-
s.version = "1.0
|
5
|
+
s.version = "1.1.0"
|
6
6
|
s.author = "Steve Shreeve"
|
7
7
|
s.email = "steve.shreeve@gmail.com"
|
8
|
-
s.summary = "An easy way to
|
8
|
+
s.summary = "An easy way to work with rows and columns as simple tables"
|
9
9
|
s.description = "This gem will auto-size based on column widths."
|
10
10
|
s.homepage = "https://github.com/shreeve/texttable"
|
11
11
|
s.license = "MIT"
|
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.1.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: 2020-
|
11
|
+
date: 2020-02-27 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
|
@@ -44,5 +44,5 @@ requirements: []
|
|
44
44
|
rubygems_version: 3.0.6
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
|
-
summary: An easy way to
|
47
|
+
summary: An easy way to work with rows and columns as simple tables
|
48
48
|
test_files: []
|