ttable 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee884467d48100b295bd4d3d5b9ca21a651d1ad8
4
- data.tar.gz: c2c5fd97bfbe4014b47e19a5c4d2bfd76da0c68f
3
+ metadata.gz: 848ced9a6e3d3713df2705bc0c1e2d09e8480962
4
+ data.tar.gz: 842f58e9371c834e36755738b686db91a813b1e7
5
5
  SHA512:
6
- metadata.gz: 21fc5f06070be22a6785e9c616176f2d0d07a53c1eec7d01f879e65a1f2c6bd5ed242c55fc3bd45a1857e37d049d8422851987d8d0fc369c90d4653c1c8c42a8
7
- data.tar.gz: 702dcf5e24dd764d30b926cf7fad809e18ab62147fd44c9ed28cc60db81a43964370e6d0ff8cb58d90a5100af85261d02fc07752b0a864e14b96bec5096ccb3d
6
+ metadata.gz: 91fd34dcb375c8cad28523e5965233f6452a16d3e503a6a4784f0bfe29d2914fec3bd86e1b19ffb3f9aa91685b631fd87b8416453f7be653d75147c2dd6359eb
7
+ data.tar.gz: 0b9a31805ecb628a1893028f985ba310d0409b3563be5fc3e52de9702f79af0f6c7edae956762f8f76c260da3a15f4fe5d6d60fe783c68d082097ae6349b94bc
data/README.md CHANGED
@@ -28,6 +28,10 @@ Or install it yourself as:
28
28
 
29
29
  TODO: Write usage instructions here
30
30
 
31
+ ## TODO
32
+
33
+ - handle new lines properly
34
+
31
35
  ## Contributing
32
36
 
33
37
  1. Fork it ( https://github.com/[my-github-username]/ttable/fork )
@@ -19,7 +19,12 @@ class String
19
19
  chars.inject(result) do |result, c|
20
20
  if c.ord <= 126
21
21
  result += 1
22
- elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ }.include?(c)
22
+ elsif %w{ ͡ ͜ }.include?(c)
23
+ # zero width
24
+ result += 0
25
+ elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ ※ ◎ ◆ ‘ ★ ’ — ° ʖ ¯ ≥ ≤ }.include?(c)
26
+ result += 1
27
+ elsif c == ' ' # ord == 8198
23
28
  result += 1
24
29
  elsif Emoji.find_by_unicode(c)
25
30
  result += 1
@@ -40,8 +45,6 @@ end
40
45
 
41
46
  module Terminal
42
47
  class Table
43
- VERSION = '0.0.2'
44
-
45
48
  attr_accessor :rows
46
49
  attr_accessor :headings
47
50
  attr_accessor :column_widths
@@ -54,6 +57,16 @@ module Terminal
54
57
  recalculate_column_widths!
55
58
  end
56
59
 
60
+ def rows=(rows)
61
+ @rows = rows.map { |row| row.map { |item| item.to_s.gsub("\n", " ") } }
62
+ recalculate_column_widths!
63
+ end
64
+
65
+ def headings=(headings)
66
+ @headings = headings
67
+ recalculate_column_widths!
68
+ end
69
+
57
70
  def recalculate_column_widths!
58
71
  if @rows.count > 0
59
72
  (0...@rows.first.size).each do |col|
@@ -0,0 +1,5 @@
1
+ module Terminal
2
+ class Table
3
+ VERSION = '0.0.3'
4
+ end
5
+ end
data/lib/ttable.rb CHANGED
@@ -1,2 +1,2 @@
1
- require "ttable/version"
1
+ require "terminal/table/version"
2
2
  require "terminal/table"
@@ -12,10 +12,43 @@ module Terminal
12
12
  its(:to_s) { should == "++\n++\n" }
13
13
  end
14
14
 
15
+ context 'new lines' do
16
+ subject { Table.new { |t| t.rows = [["a\nb"]] } }
17
+
18
+ expected = <<END
19
+ +-----+
20
+ | a b |
21
+ +-----+
22
+ END
23
+ its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
24
+ end
25
+
15
26
  context 'when only heading' do
16
27
  subject { Table.new { |t| t.headings = %w{ head } } }
17
28
  its(:to_s) { should == "+------+\n| head |\n+------+\n+------+\n" }
18
29
  end
30
+
31
+ context 'when set contents after' do
32
+ subject { Table.new.tap { |t| t.headings = %w{ head } } }
33
+ its(:to_s) { should == "+------+\n| head |\n+------+\n+------+\n" }
34
+ end
35
+
36
+ context 'with nil values' do
37
+ subject { Table.new { |t| t.headings = %w{ head }; t.rows = [ [ nil ] ] } }
38
+ its(:to_s) { should == "+------+\n| head |\n+------+\n| |\n+------+\n" }
39
+ end
40
+
41
+ context 'with nil values' do
42
+ subject { Table.new { |t| t.headings = %w{ head1 head2 }; t.rows = [ [ nil, nil ] ] } }
43
+ expected = <<END
44
+ +-------+-------+
45
+ | head1 | head2 |
46
+ +-------+-------+
47
+ | | |
48
+ +-------+-------+
49
+ END
50
+ its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
51
+ end
19
52
  end
20
53
  end
21
54
  end
@@ -76,5 +109,60 @@ describe String do
76
109
  subject { '☻' }
77
110
  its(:twidth) { should == 1 }
78
111
  end
112
+
113
+ context '※' do
114
+ subject { '※' }
115
+ its(:twidth) { should == 1 }
116
+ end
117
+
118
+ context '◎' do
119
+ subject { '◎' }
120
+ its(:twidth) { should == 1 }
121
+ end
122
+
123
+ context '◆' do
124
+ subject { '◆' }
125
+ its(:twidth) { should == 1 }
126
+ end
127
+
128
+ context '‘' do
129
+ subject { '‘' }
130
+ its(:twidth) { should == 1 }
131
+ end
132
+
133
+ context '★ ’' do
134
+ subject { '★ ’' }
135
+ its(:twidth) { should == 3 }
136
+ end
137
+
138
+ context '—' do
139
+ subject { '—' }
140
+ its(:twidth) { should == 1 }
141
+ end
142
+
143
+ context 'special whitespace' do
144
+ subject { ' ' }
145
+ its(:twidth) { should == 1 }
146
+ end
147
+
148
+ context ' ͡° ͜ʖ ͡°' do
149
+ subject { ' ͡° ͜ʖ ͡°' }
150
+ its(:twidth) { should == 6 }
151
+ end
152
+
153
+ context '(¯﹃¯)' do
154
+ subject { '(¯﹃¯)' }
155
+ its(:twidth) { should == 8 }
156
+ end
157
+
158
+ context '()' do
159
+ subject { '()' }
160
+ its(:twidth) { should == 4 }
161
+ end
162
+
163
+ context '≥≤' do
164
+ subject { '≥≤' }
165
+ its(:twidth) { should == 2 }
166
+ end
79
167
  end
80
168
  end
data/ttable.gemspec CHANGED
@@ -1,7 +1,7 @@
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 'terminal/table'
4
+ require 'terminal/table/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ttable"
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.2
4
+ version: 0.0.3
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-10-15 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,7 @@ files:
69
69
  - Rakefile
70
70
  - bin/ttable
71
71
  - lib/terminal/table.rb
72
+ - lib/terminal/table/version.rb
72
73
  - lib/ttable.rb
73
74
  - screenshot.png
74
75
  - spec/spec_helper.rb