ttable 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +2 -1
- data/README.md +4 -0
- data/Rakefile +0 -1
- data/lib/terminal/table.rb +15 -4
- data/spec/spec_helper.rb +6 -0
- data/spec/terminal/table_spec.rb +73 -0
- data/ttable.gemspec +2 -2
- metadata +3 -3
- data/lib/ttable/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee884467d48100b295bd4d3d5b9ca21a651d1ad8
|
4
|
+
data.tar.gz: c2c5fd97bfbe4014b47e19a5c4d2bfd76da0c68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21fc5f06070be22a6785e9c616176f2d0d07a53c1eec7d01f879e65a1f2c6bd5ed242c55fc3bd45a1857e37d049d8422851987d8d0fc369c90d4653c1c8c42a8
|
7
|
+
data.tar.gz: 702dcf5e24dd764d30b926cf7fad809e18ab62147fd44c9ed28cc60db81a43964370e6d0ff8cb58d90a5100af85261d02fc07752b0a864e14b96bec5096ccb3d
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# ttable
|
2
2
|
|
3
|
+
[](https://codeclimate.com/github/forresty/ttable)
|
4
|
+
[](https://coveralls.io/r/forresty/ttable)
|
5
|
+
[](https://travis-ci.org/forresty/ttable)
|
6
|
+
|
3
7
|
See it in action:
|
4
8
|
|
5
9
|

|
data/Rakefile
CHANGED
data/lib/terminal/table.rb
CHANGED
@@ -4,13 +4,22 @@ require "gemoji"
|
|
4
4
|
|
5
5
|
class String
|
6
6
|
def twidth
|
7
|
-
|
8
|
-
|
7
|
+
result = 0
|
8
|
+
|
9
|
+
# 4 code point emoji
|
10
|
+
%w{ ☺️ ❤️ }.each do |c|
|
11
|
+
result += -3 * scan(c).size
|
12
|
+
end
|
13
|
+
|
14
|
+
# 3 code point emoji
|
15
|
+
%w{ ♍️ }.each do |c|
|
16
|
+
result += -2 * scan(c).size
|
17
|
+
end
|
9
18
|
|
10
19
|
chars.inject(result) do |result, c|
|
11
20
|
if c.ord <= 126
|
12
21
|
result += 1
|
13
|
-
elsif %w{ • é · ♪ … ω ˊ ˋ }.include?(c)
|
22
|
+
elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ }.include?(c)
|
14
23
|
result += 1
|
15
24
|
elsif Emoji.find_by_unicode(c)
|
16
25
|
result += 1
|
@@ -31,6 +40,8 @@ end
|
|
31
40
|
|
32
41
|
module Terminal
|
33
42
|
class Table
|
43
|
+
VERSION = '0.0.2'
|
44
|
+
|
34
45
|
attr_accessor :rows
|
35
46
|
attr_accessor :headings
|
36
47
|
attr_accessor :column_widths
|
@@ -52,7 +63,7 @@ module Terminal
|
|
52
63
|
|
53
64
|
if @headings.count > 0
|
54
65
|
(0...@headings.size).each do |col|
|
55
|
-
@column_widths[col] = [@column_widths[col], @headings[col].twidth].max
|
66
|
+
@column_widths[col] = [@column_widths[col] || 0, @headings[col].twidth].max
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/terminal/table_spec.rb
CHANGED
@@ -1,7 +1,80 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
module Terminal
|
4
6
|
describe Table do
|
5
7
|
it { should respond_to :to_s }
|
8
|
+
|
9
|
+
describe '#to_s' do
|
10
|
+
context 'when empty' do
|
11
|
+
subject { Table.new }
|
12
|
+
its(:to_s) { should == "++\n++\n" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when only heading' do
|
16
|
+
subject { Table.new { |t| t.headings = %w{ head } } }
|
17
|
+
its(:to_s) { should == "+------+\n| head |\n+------+\n+------+\n" }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe String do
|
24
|
+
describe '#twidth' do
|
25
|
+
context 'C' do
|
26
|
+
subject { 'C' }
|
27
|
+
its(:twidth) { should == 2 }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'ě' do
|
31
|
+
subject { 'ě' }
|
32
|
+
its(:twidth) { should == 1 }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'l' do
|
36
|
+
subject { 'l' }
|
37
|
+
its(:twidth) { should == 2 }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'ì' do
|
41
|
+
subject { 'ì' }
|
42
|
+
its(:twidth) { should == 1 }
|
43
|
+
end
|
44
|
+
|
45
|
+
context '☺️' do
|
46
|
+
subject { '☺️' }
|
47
|
+
its(:twidth) { should == 1 }
|
48
|
+
end
|
49
|
+
|
50
|
+
context '❤️' do
|
51
|
+
subject { '❤️' }
|
52
|
+
its(:twidth) { should == 1 }
|
53
|
+
end
|
54
|
+
|
55
|
+
context '√' do
|
56
|
+
subject { '√' }
|
57
|
+
its(:twidth) { should == 1 }
|
58
|
+
end
|
59
|
+
|
60
|
+
context '”' do
|
61
|
+
subject { '”' }
|
62
|
+
its(:twidth) { should == 1 }
|
63
|
+
end
|
64
|
+
|
65
|
+
context '“' do
|
66
|
+
subject { '“' }
|
67
|
+
its(:twidth) { should == 1 }
|
68
|
+
end
|
69
|
+
|
70
|
+
context '♍️' do
|
71
|
+
subject { '♍️' }
|
72
|
+
its(:twidth) { should == 1 }
|
73
|
+
end
|
74
|
+
|
75
|
+
context '☻' do
|
76
|
+
subject { '☻' }
|
77
|
+
its(:twidth) { should == 1 }
|
78
|
+
end
|
6
79
|
end
|
7
80
|
end
|
data/ttable.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'terminal/table'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ttable"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Terminal::Table::VERSION
|
9
9
|
spec.authors = ["Forrest Ye"]
|
10
10
|
spec.email = ["afu@forresty.com"]
|
11
11
|
spec.summary = %q{Terminal Table with @2x width character support}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Forrest Ye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- .gitignore
|
64
|
+
- .travis.yml
|
64
65
|
- Gemfile
|
65
66
|
- Guardfile
|
66
67
|
- LICENSE.txt
|
@@ -69,7 +70,6 @@ files:
|
|
69
70
|
- bin/ttable
|
70
71
|
- lib/terminal/table.rb
|
71
72
|
- lib/ttable.rb
|
72
|
-
- lib/ttable/version.rb
|
73
73
|
- screenshot.png
|
74
74
|
- spec/spec_helper.rb
|
75
75
|
- spec/terminal/table_spec.rb
|
data/lib/ttable/version.rb
DELETED