texttable 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -2
  3. data/lib/texttable.rb +17 -7
  4. data/texttable.gemspec +2 -2
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b13d92731fd1e953796cf41617ba4ab824e35f8ea13cf6051afed26ce57d79
4
- data.tar.gz: d68b96bc1e91868f29628f02d1702b111e8e5cf14adb8298800aba9cc204f903
3
+ metadata.gz: 7dc849d43312afb4106b6db6908f154f937409c3ac780a6d2ee36645f7155e7d
4
+ data.tar.gz: d947accbe4d63f66d6c9d321aa96f8936a594d4c5a3e34dd05259b61645bb3c7
5
5
  SHA512:
6
- metadata.gz: 50f8d09be9eff3c49f71c7ecb92d907338f847593696f5b04c5ef815e9d478ee4a9597260dae74ddb427041be7f08feac78a55c8457fecdc2b8f3283ad69b5d6
7
- data.tar.gz: 90e8f6974539d3b5fd4c216be960b7b89c4f74ddcf37c6fdae8505cff8d356b6ee5cd0db050e12dead18e9cf14d58341559c068ed1870dac10ec2604b49722b2
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 print rows and columns as simple tables.
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
- ## Examples
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
- 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 = []
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.7"
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 print rows and columns as simple tables"
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.7
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-01-15 00:00:00.000000000 Z
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 print rows and columns as simple tables
47
+ summary: An easy way to work with rows and columns as simple tables
48
48
  test_files: []