ttable 0.0.6 → 0.0.7
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/Guardfile +1 -1
- data/README.md +1 -0
- data/lib/terminal/table.rb +14 -12
- data/lib/terminal/table/version.rb +1 -1
- data/spec/terminal/table_spec.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1143d0826e56fc391aab77df86ae4bb65d60e4b7
|
4
|
+
data.tar.gz: d9dd441bc44c6acbd8ebc16627b18fab37a05c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6c57c1f6bcd67303b255c6a1ae59b979ce0f4526f5af3245ef267242ead715be3249a55d6ebf97d201f03728b26cf0d97e686a3238975770e575beac18f82b2
|
7
|
+
data.tar.gz: dd5306f3053de63bf39403b8eabde5f3f97ca143ce8327ce289bebbf4ed55cd35482489f37e2d45fb9e08a5601290092d884b63a202daf1d433d109107439e32
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://codeclimate.com/github/forresty/ttable)
|
4
4
|
[](https://coveralls.io/r/forresty/ttable)
|
5
5
|
[](https://travis-ci.org/forresty/ttable)
|
6
|
+
[](http://badge.fury.io/rb/ttable)
|
6
7
|
|
7
8
|
See it in action:
|
8
9
|
|
data/lib/terminal/table.rb
CHANGED
@@ -19,7 +19,7 @@ class String
|
|
19
19
|
elsif %w{ ͡ ͜ }.include?(c)
|
20
20
|
# zero width
|
21
21
|
result += 0
|
22
|
-
elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ ※ ◎ ◆ ‘ ★ ’ — ° ʖ ¯ ≥ ≤ ≧ ∇ ≦ ❤ ☺ ╭ ╯ ε ╰ ╮ з ∠ → ☞ ë ϵ Θ ϶ }.include?(c)
|
22
|
+
elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ ※ ◎ ◆ ‘ ★ ’ — ° ʖ ¯ ≥ ≤ ≧ ∇ ≦ ❤ ☺ ╭ ╯ ε ╰ ╮ з ∠ → ☞ ë ϵ Θ ϶ Ο Ι }.include?(c)
|
23
23
|
result += 1
|
24
24
|
elsif c == ' ' # ord == 8198
|
25
25
|
result += 1
|
@@ -50,9 +50,10 @@ module Terminal
|
|
50
50
|
@rows = []
|
51
51
|
@headings = []
|
52
52
|
@column_widths = []
|
53
|
-
|
54
53
|
if object
|
55
|
-
if object.
|
54
|
+
if object.is_a?(Hash)
|
55
|
+
add_hash(object, options)
|
56
|
+
elsif object.respond_to?(:each)
|
56
57
|
object.each { |o| add_object(o, options) }
|
57
58
|
else
|
58
59
|
add_object(object, options)
|
@@ -64,17 +65,18 @@ module Terminal
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def add_object(object, options)
|
67
|
-
if object.respond_to?(:to_hash)
|
68
|
-
|
69
|
-
if options[:only]
|
70
|
-
hash.keep_if { |k, v| options[:only].map(&:to_sym).include?(k) }
|
71
|
-
elsif options[:except]
|
72
|
-
hash.delete_if { |k, v| options[:except].map(&:to_sym).include?(k) }
|
73
|
-
end
|
68
|
+
add_hash(object.to_hash, options) if object.respond_to?(:to_hash)
|
69
|
+
end
|
74
70
|
|
75
|
-
|
76
|
-
|
71
|
+
def add_hash(hash, options)
|
72
|
+
if options[:only]
|
73
|
+
hash.keep_if { |k, v| options[:only].map(&:to_sym).include?(k) }
|
74
|
+
elsif options[:except]
|
75
|
+
hash.delete_if { |k, v| options[:except].map(&:to_sym).include?(k) }
|
77
76
|
end
|
77
|
+
|
78
|
+
@headings = hash.keys.map(&:to_s)
|
79
|
+
@rows << hash.values
|
78
80
|
end
|
79
81
|
|
80
82
|
def headings=(headings)
|
data/spec/terminal/table_spec.rb
CHANGED
@@ -22,6 +22,38 @@ module Terminal
|
|
22
22
|
describe Table do
|
23
23
|
it { should respond_to :to_s }
|
24
24
|
|
25
|
+
describe 'initialize with hash' do
|
26
|
+
let(:hash) { { foo: 'bar' } }
|
27
|
+
|
28
|
+
subject { Table.new(hash) }
|
29
|
+
|
30
|
+
expected = <<END
|
31
|
+
+-----+
|
32
|
+
| foo |
|
33
|
+
+-----+
|
34
|
+
| bar |
|
35
|
+
+-----+
|
36
|
+
END
|
37
|
+
its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'initialize with array of hashes' do
|
41
|
+
let(:hash1) { { foo: 'bar1' } }
|
42
|
+
let(:hash2) { { foo: 'bar2' } }
|
43
|
+
|
44
|
+
subject { Table.new([hash1, hash2]) }
|
45
|
+
|
46
|
+
expected = <<END
|
47
|
+
+------+
|
48
|
+
| foo |
|
49
|
+
+------+
|
50
|
+
| bar1 |
|
51
|
+
| bar2 |
|
52
|
+
+------+
|
53
|
+
END
|
54
|
+
its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
|
55
|
+
end
|
56
|
+
|
25
57
|
describe 'initialize with object#to_hash' do
|
26
58
|
let(:object) { Dummy.new.tap { |d| d.foo = 'bar' } }
|
27
59
|
subject { Table.new(object) }
|
@@ -357,5 +389,10 @@ describe String do
|
|
357
389
|
subject { "ϵ( 'Θ' )϶" }
|
358
390
|
its(:twidth) { should == 9 }
|
359
391
|
end
|
392
|
+
|
393
|
+
context 'にΟΙ' do
|
394
|
+
subject { 'にΟΙ' }
|
395
|
+
its(:twidth) { should == 4 }
|
396
|
+
end
|
360
397
|
end
|
361
398
|
end
|
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.7
|
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-
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|