tabularize 0.2.2 → 0.2.4
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.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/tabularize.rb +98 -34
- data/lib/tabularize/version.rb +1 -1
- data/test/fixture/tabularize_csv.txt +56 -0
- data/test/{test.csv → fixture/test.csv} +0 -0
- data/test/{test_unicode.csv → fixture/test_unicode.csv} +0 -0
- data/test/{test_unicode_ansi.csv → fixture/test_unicode_ansi.csv} +0 -0
- data/test/test_tabularize.rb +86 -24
- metadata +10 -8
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/tabularize.rb
CHANGED
@@ -33,6 +33,7 @@ class Tabularize
|
|
33
33
|
@options = DEFAULT_OPTIONS.
|
34
34
|
merge(DEFAULT_OPTIONS_GENERATOR).
|
35
35
|
merge(options)
|
36
|
+
@cache = {}
|
36
37
|
end
|
37
38
|
|
38
39
|
# @since 0.2.0
|
@@ -51,8 +52,31 @@ class Tabularize
|
|
51
52
|
# @return [String]
|
52
53
|
# @since 0.2.0
|
53
54
|
def to_s
|
54
|
-
|
55
|
-
|
55
|
+
return nil if @rows.empty?
|
56
|
+
|
57
|
+
# Invalidate cache if needed
|
58
|
+
num_cached_rows = @cache[:num_rows] || 0
|
59
|
+
analysis = Tabularize.analyze(@rows[num_cached_rows..-1], @options.merge(@cache[:analysis] || {}))
|
60
|
+
|
61
|
+
unless @cache.empty?
|
62
|
+
cmw = @cache[:analysis][:max_widths]
|
63
|
+
mw = analysis[:max_widths]
|
64
|
+
if mw.zip(cmw).any? { |pair| pair.first > (pair.last || 0) }
|
65
|
+
@cache = {}
|
66
|
+
num_cached_rows = 0
|
67
|
+
else
|
68
|
+
[@seps[@rows.length] - @cache[:last_seps], 0].max.times do
|
69
|
+
@cache[:string_io].puts @cache[:separator]
|
70
|
+
end
|
71
|
+
@cache[:last_seps] = @seps[@rows.length]
|
72
|
+
|
73
|
+
if num_cached_rows == @rows.length
|
74
|
+
return @cache[:string_io].string + @cache[:separator]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
rows = Tabularize.it(@rows[num_cached_rows..-1], @options.merge(analysis))
|
56
80
|
|
57
81
|
h = @options[:hborder]
|
58
82
|
v = @options[:vborder]
|
@@ -64,26 +88,32 @@ class Tabularize
|
|
64
88
|
sw = @options[:screen_width]
|
65
89
|
el = @options[:ellipsis].length
|
66
90
|
|
67
|
-
separator =
|
68
|
-
|
69
|
-
|
91
|
+
separator = @cache[:separator]
|
92
|
+
col_count = @cache[:col_count]
|
93
|
+
unless separator
|
94
|
+
separator = ''
|
95
|
+
rows[0].each_with_index do |c, idx|
|
96
|
+
new_sep = separator + i + h * Tabularize.cell_width(c, u, a)
|
70
97
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
98
|
+
if sw && Tabularize.cell_width(new_sep, u, a) > sw - el
|
99
|
+
col_count = idx
|
100
|
+
break
|
101
|
+
else
|
102
|
+
separator = new_sep
|
103
|
+
end
|
77
104
|
end
|
105
|
+
separator += il
|
78
106
|
end
|
79
|
-
separator += il
|
80
107
|
|
81
|
-
output = StringIO.new
|
82
|
-
|
108
|
+
output = @cache[:string_io] || StringIO.new.tap { |io| io.puts separator }
|
109
|
+
if col_count
|
110
|
+
rows = rows.map { |line| line[0, col_count] }
|
111
|
+
vl = il = @options[:ellipsis]
|
112
|
+
end
|
83
113
|
rows.each_with_index do |row, idx|
|
84
114
|
row = row.map { |val| val.lines.to_a.map(&:chomp) }
|
85
115
|
height = row[0] ? row[0].count : 1
|
86
|
-
@seps[idx].times do
|
116
|
+
@seps[idx + num_cached_rows].times do
|
87
117
|
output.puts separator
|
88
118
|
end
|
89
119
|
(0...height).each do |line|
|
@@ -94,12 +124,22 @@ class Tabularize
|
|
94
124
|
end
|
95
125
|
end
|
96
126
|
|
97
|
-
@seps[rows.length].times do
|
127
|
+
@seps[rows.length + num_cached_rows].times do
|
98
128
|
output.puts separator
|
99
129
|
end
|
100
130
|
|
101
|
-
|
102
|
-
|
131
|
+
@cache = {
|
132
|
+
:analysis => analysis,
|
133
|
+
:separator => separator,
|
134
|
+
:col_count => col_count,
|
135
|
+
:num_rows => @rows.length,
|
136
|
+
:string_io => output,
|
137
|
+
:last_seps => @seps[rows.length]
|
138
|
+
}
|
139
|
+
output.string + separator
|
140
|
+
rescue Exception
|
141
|
+
@cache = {}
|
142
|
+
raise
|
103
143
|
end
|
104
144
|
|
105
145
|
# Returns the display width of a String
|
@@ -113,6 +153,41 @@ class Tabularize
|
|
113
153
|
str.send(unicode ? :display_width : :length)
|
114
154
|
end
|
115
155
|
|
156
|
+
# Determines maximum widths of cells and maximum heights of rows
|
157
|
+
def self.analyze data, options = {}
|
158
|
+
unicode = options[:unicode]
|
159
|
+
ansi = options[:ansi]
|
160
|
+
max_widths = (options[:max_widths] || []).dup
|
161
|
+
max_heights = (options[:max_heights] || []).dup
|
162
|
+
rows = []
|
163
|
+
|
164
|
+
data.each_with_index do |row, ridx|
|
165
|
+
rows << row = [*row].map(&:to_s)
|
166
|
+
|
167
|
+
row.each_with_index do |cell, idx|
|
168
|
+
nlines = 0
|
169
|
+
cell.lines do |c|
|
170
|
+
max_widths[idx] = [ Tabularize.cell_width(c.chomp, unicode, ansi), max_widths[idx] || 0 ].max
|
171
|
+
nlines += 1
|
172
|
+
end
|
173
|
+
max_heights[ridx] = [ nlines, max_heights[ridx] || 1 ].max
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
num_cells = max_widths.length
|
178
|
+
rows.each do |row|
|
179
|
+
[num_cells - row.length, 0].max.times do
|
180
|
+
row << ''
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
{
|
185
|
+
:rows => rows,
|
186
|
+
:max_widths => max_widths,
|
187
|
+
:max_heights => max_heights,
|
188
|
+
}
|
189
|
+
end
|
190
|
+
|
116
191
|
# Formats two-dimensional tabular data.
|
117
192
|
# One-dimensional data (e.g. Array of Strings) is treated as tabular data
|
118
193
|
# of which each row has only one column.
|
@@ -152,21 +227,10 @@ class Tabularize
|
|
152
227
|
raise ArgumentError.new(":screen_width must be a positive integer")
|
153
228
|
end
|
154
229
|
|
155
|
-
|
156
|
-
|
157
|
-
max_heights =
|
158
|
-
|
159
|
-
rows << row = [*row].map(&:to_s)
|
160
|
-
|
161
|
-
row.each_with_index do |cell, idx|
|
162
|
-
nlines = 0
|
163
|
-
cell.lines do |c|
|
164
|
-
max_widths[idx] = [ Tabularize.cell_width(c.chomp, unicode, ansi), max_widths[idx] || 0 ].max
|
165
|
-
nlines += 1
|
166
|
-
end
|
167
|
-
max_heights[ridx] = [ nlines, max_heights[ridx] || 1 ].max
|
168
|
-
end
|
169
|
-
end
|
230
|
+
# Analyze data
|
231
|
+
ret = options[:analysis] || Tabularize.analyze(table_data, options)
|
232
|
+
rows, max_widths, max_heights =
|
233
|
+
[:rows, :max_widths, :max_heights].map { |k| ret[k] }
|
170
234
|
|
171
235
|
ridx = -1
|
172
236
|
rows.map { |row|
|
@@ -175,7 +239,7 @@ class Tabularize
|
|
175
239
|
max_height = max_heights[ridx]
|
176
240
|
row.map { |cell|
|
177
241
|
idx += 1
|
178
|
-
lines = cell.lines.to_a
|
242
|
+
lines = cell.to_s.lines.to_a
|
179
243
|
offset =
|
180
244
|
case valign[idx] || valign.last
|
181
245
|
when :top
|
data/lib/tabularize/version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
Name |Dept |Location |Phone
|
2
|
+
John Doe |Finance |Los Angeles, CA 90089 |555-1555
|
3
|
+
Average Joe |Engineering|Somewhere over the rainbow|N/A
|
4
|
+
Hong Gildong|HR |Nowhere |555-5555
|
5
|
+
Name| Dept| Location| Phone
|
6
|
+
John Doe| Finance| Los Angeles, CA 90089|555-1555
|
7
|
+
Average Joe|Engineering|Somewhere over the rainbow| N/A
|
8
|
+
Hong Gildong| HR| Nowhere|555-5555
|
9
|
+
Name | Dept | Location | Phone
|
10
|
+
John Doe | Finance | Los Angeles, CA 90089 |555-1555
|
11
|
+
Average Joe |Engineering|Somewhere over the rainbow| N/A
|
12
|
+
Hong Gildong| HR | Nowhere |555-5555
|
13
|
+
Name________|Dept_______|Location__________________|Phone___
|
14
|
+
John Doe____|Finance____|Los Angeles, CA 90089_____|555-1555
|
15
|
+
Average Joe_|Engineering|Somewhere over the rainbow|N/A_____
|
16
|
+
Hong Gildong|HR_________|Nowhere___________________|555-5555
|
17
|
+
Name |Dept |Location |Phone
|
18
|
+
John Doe |Finance |Los Angeles, CA 90089 |555-1555
|
19
|
+
Average Joe |Engineering|Somewhere over the rainbow |N/A
|
20
|
+
Hong Gildong|HR |Nowhere |555-5555
|
21
|
+
홍길동 |탁상 3부 |서울역 3번 출구 김씨 옆자리|N/A
|
22
|
+
Name| Dept| Location| Phone
|
23
|
+
John Doe| Finance| Los Angeles, CA 90089|555-1555
|
24
|
+
Average Joe|Engineering| Somewhere over the rainbow| N/A
|
25
|
+
Hong Gildong| HR| Nowhere|555-5555
|
26
|
+
홍길동| 탁상 3부|서울역 3번 출구 김씨 옆자리| N/A
|
27
|
+
Name | Dept | Location | Phone
|
28
|
+
John Doe | Finance | Los Angeles, CA 90089 |555-1555
|
29
|
+
Average Joe |Engineering|Somewhere over the rainbow | N/A
|
30
|
+
Hong Gildong| HR | Nowhere |555-5555
|
31
|
+
홍길동 | 탁상 3부 |서울역 3번 출구 김씨 옆자리| N/A
|
32
|
+
Name________|Dept_______|Location___________________|Phone___
|
33
|
+
John Doe____|Finance____|Los Angeles, CA 90089______|555-1555
|
34
|
+
Average Joe_|Engineering|Somewhere over the rainbow_|N/A_____
|
35
|
+
Hong Gildong|HR_________|Nowhere____________________|555-5555
|
36
|
+
홍길동______|탁상 3부___|서울역 3번 출구 김씨 옆자리|N/A_____
|
37
|
+
Name |Dept |Location |Phone
|
38
|
+
[31mJohn Doe[0m |Finance |Los Angeles, CA 90089 |555-1555
|
39
|
+
Average Joe |[31m[1m[4m[42mEngineering[0m|Somewhere over the rainbow |N/A
|
40
|
+
Hong Gildong|[31m[1mHR[0m |Nowhere |555-5555
|
41
|
+
[31m[1m[4m[42m홍길동[0m |탁상 3부 |서울역 3번 출구 김씨 옆자리|N/A
|
42
|
+
Name| Dept| Location| Phone
|
43
|
+
[31mJohn Doe[0m| Finance| Los Angeles, CA 90089|555-1555
|
44
|
+
Average Joe|[31m[1m[4m[42mEngineering[0m| Somewhere over the rainbow| N/A
|
45
|
+
Hong Gildong| [31m[1mHR[0m| Nowhere|555-5555
|
46
|
+
[31m[1m[4m[42m홍길동[0m| 탁상 3부|서울역 3번 출구 김씨 옆자리| N/A
|
47
|
+
Name | Dept | Location | Phone
|
48
|
+
[31mJohn Doe[0m | Finance | Los Angeles, CA 90089 |555-1555
|
49
|
+
Average Joe |[31m[1m[4m[42mEngineering[0m|Somewhere over the rainbow | N/A
|
50
|
+
Hong Gildong| [31m[1mHR[0m | Nowhere |555-5555
|
51
|
+
[31m[1m[4m[42m홍길동[0m | 탁상 3부 |서울역 3번 출구 김씨 옆자리| N/A
|
52
|
+
Name________|Dept_______|Location___________________|Phone___
|
53
|
+
[31mJohn Doe[0m____|Finance____|Los Angeles, CA 90089______|555-1555
|
54
|
+
Average Joe_|[31m[1m[4m[42mEngineering[0m|Somewhere over the rainbow_|N/A_____
|
55
|
+
Hong Gildong|[31m[1mHR[0m_________|Nowhere____________________|555-5555
|
56
|
+
[31m[1m[4m[42m홍길동[0m______|탁상 3부___|서울역 3번 출구 김씨 옆자리|N/A_____
|
File without changes
|
File without changes
|
File without changes
|
data/test/test_tabularize.rb
CHANGED
@@ -68,22 +68,22 @@ class TestTabularize < Test::Unit::TestCase
|
|
68
68
|
:left =>
|
69
69
|
[
|
70
70
|
"a |aa |aaa|aaaa",
|
71
|
-
"cccccccccccccccccccc",
|
72
|
-
"ddd |dddd|d ",
|
71
|
+
"cccccccccccccccccccc| | | ",
|
72
|
+
"ddd |dddd|d | ",
|
73
73
|
"bbbb |bbb |bb |b "
|
74
74
|
],
|
75
75
|
:right =>
|
76
76
|
[
|
77
77
|
" a| aa|aaa|aaaa",
|
78
|
-
"cccccccccccccccccccc",
|
79
|
-
" ddd|dddd| d",
|
78
|
+
"cccccccccccccccccccc| | | ",
|
79
|
+
" ddd|dddd| d| ",
|
80
80
|
" bbbb| bbb| bb| b"
|
81
81
|
],
|
82
82
|
:center =>
|
83
83
|
[
|
84
84
|
" a | aa |aaa|aaaa",
|
85
|
-
"cccccccccccccccccccc",
|
86
|
-
" ddd |dddd| d ",
|
85
|
+
"cccccccccccccccccccc| | | ",
|
86
|
+
" ddd |dddd| d | ",
|
87
87
|
" bbbb |bbb |bb | b "
|
88
88
|
]
|
89
89
|
}
|
@@ -96,36 +96,47 @@ class TestTabularize < Test::Unit::TestCase
|
|
96
96
|
[ '.', '_' ].each do |pad|
|
97
97
|
[:left, :right, :center].each do |align|
|
98
98
|
result = Tabularize.it(data, :pad => pad, :align => align)
|
99
|
-
ap :align => align, :pad => pad, :from => data, :to => result.map { |r| r.join('|') }
|
100
99
|
assert_equal RESULT[data][align], result.map { |row| row.join('|').gsub(pad, ' ') }
|
101
100
|
end
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
105
|
+
def test_analyze
|
106
|
+
data = []
|
107
|
+
data << %w[a bb ccc]
|
108
|
+
data << %w[aa bb cc]
|
109
|
+
data << %w[aaa bb cc]
|
110
|
+
data << %w[aaa bb cc] + ["dddd\neee"]
|
111
|
+
data << %w[f]
|
112
|
+
ret = Tabularize.analyze(data, :unicode => true, :ansi => true)
|
113
|
+
assert_equal [%w[a bb ccc].push(''), %w[aa bb cc].push(''), %w[aaa bb cc].push(''),
|
114
|
+
%w[aaa bb cc] + ["dddd\neee"], %w[f] + [''] * 3], ret[:rows]
|
115
|
+
assert_equal [1, 1, 1, 2, 1], ret[:max_heights]
|
116
|
+
assert_equal [3, 2, 3, 4], ret[:max_widths]
|
117
|
+
end
|
118
|
+
|
106
119
|
# TODO: Need assertion
|
107
120
|
def test_tabularize_csv
|
121
|
+
sio = StringIO.new
|
122
|
+
|
108
123
|
{
|
109
|
-
'test.csv' => [false, false],
|
110
|
-
'test_unicode.csv' => [true, false],
|
111
|
-
'test_unicode_ansi.csv' => [true, true]
|
124
|
+
'fixture/test.csv' => [false, false],
|
125
|
+
'fixture/test_unicode.csv' => [true, false],
|
126
|
+
'fixture/test_unicode_ansi.csv' => [true, true]
|
112
127
|
}.each do |file, unicode_ansi|
|
113
128
|
unicode, ansi = unicode_ansi
|
114
129
|
opts = { :unicode => unicode, :ansi => ansi }
|
115
130
|
data = CSV.read(File.join(File.dirname(__FILE__), file), :col_sep => '|')
|
116
|
-
ap data
|
117
131
|
output = Tabularize.it(data, opts).map { |row| row.join '|' }
|
118
|
-
ap output
|
119
|
-
puts
|
120
|
-
puts output
|
121
|
-
|
122
|
-
puts Tabularize.it(data, opts.merge(:align => :right)).map { |row| row.join '|' }
|
123
|
-
puts
|
124
|
-
puts Tabularize.it(data, opts.merge(:align => :center)).map { |row| row.join '|' }
|
125
|
-
puts
|
126
|
-
puts Tabularize.it(data, opts.merge(:pad => '_')).map { |row| row.join '|' }
|
127
132
|
|
133
|
+
sio.puts output
|
134
|
+
sio.puts Tabularize.it(data, opts.merge(:align => :right)).map { |row| row.join '|' }
|
135
|
+
sio.puts Tabularize.it(data, opts.merge(:align => :center)).map { |row| row.join '|' }
|
136
|
+
sio.puts Tabularize.it(data, opts.merge(:pad => '_')).map { |row| row.join '|' }
|
128
137
|
end
|
138
|
+
|
139
|
+
assert_equal File.read(File.join(File.dirname(__FILE__), 'fixture/tabularize_csv.txt')), sio.string
|
129
140
|
end
|
130
141
|
|
131
142
|
def test_invalid_arguments
|
@@ -156,17 +167,29 @@ class TestTabularize < Test::Unit::TestCase
|
|
156
167
|
table << DATA2[2]
|
157
168
|
table << DATA2[3]
|
158
169
|
|
159
|
-
|
170
|
+
assert_equal(
|
171
|
+
'#============================#============#===========#============#
|
172
|
+
I,,,,,,,,,,,,a,,,,,,,,,,,,,,,I,,,,aa,,,,,,I,,,aaa,,,,,I,,,aaaa,,,,,I
|
173
|
+
#============================#============#===========#============#
|
174
|
+
I,,,,,,,,,,,,a,,,,,,,,,,,,,,,I,,,,aa,,,,,,I,,,aaa,,,,,I,,,aaaa,,,,,I
|
175
|
+
#============================#============#===========#============#
|
176
|
+
#============================#============#===========#============#
|
177
|
+
I,,,cccccccccccccccccccc,,,,,I,,,,,,,,,,,,I,,,,,,,,,,,I,,,,,,,,,,,,I
|
178
|
+
#============================#============#===========#============#
|
179
|
+
I,,,,,,,,,,,ddd,,,,,,,,,,,,,,I,,,dddd,,,,,I,,,,d,,,,,,I,,,,,,,,,,,,I
|
180
|
+
I,,,,,,,,,,,bbbb,,,,,,,,,,,,,I,,,bbb,,,,,,I,,,bb,,,,,,I,,,,b,,,,,,,I
|
181
|
+
#============================#============#===========#============#', table.to_s)
|
160
182
|
end
|
161
183
|
|
162
184
|
def test_table_complex
|
185
|
+
separator = '#~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#'
|
163
186
|
output = "
|
164
187
|
#~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
165
188
|
I..Name.......I.....Dept....I.....................LocationI.....PhoneI
|
166
189
|
#~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
167
190
|
I..John Doe...I....Finance..I.........Los Angeles CA 90089I..555-1555I
|
168
191
|
I..Average JoeI..EngineeringI...Somewhere over the rainbowI.......N/AI
|
169
|
-
I..1..........I
|
192
|
+
I..1..........I.............I.............................I..........I
|
170
193
|
#~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
171
194
|
#~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
172
195
|
I..홍길동.....I.............I..서울역 3번 출구 김씨 옆자리I..........I
|
@@ -191,17 +214,56 @@ I.............I...탁상 3부..I.....................맞습니다I..........I
|
|
191
214
|
table << ['홍길동', '탁상 3부', "서울역 3번 출구 김씨 옆자리\n\n맞습니다", 'N/A']
|
192
215
|
table.separator!
|
193
216
|
table.separator!
|
217
|
+
|
218
|
+
100.times do
|
219
|
+
assert_equal output, table.to_s.strip
|
220
|
+
end
|
221
|
+
table.separator!
|
222
|
+
table.separator!
|
223
|
+
assert_equal [output, separator, separator].join($/), table.to_s.strip
|
224
|
+
assert_equal [output, separator, separator].join($/), table.to_s.strip
|
225
|
+
table << "This should change everything doh!"
|
226
|
+
output = "
|
227
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
228
|
+
I..Name..............................I.....Dept....I.....................LocationI.....PhoneI
|
229
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
230
|
+
I..John Doe..........................I....Finance..I.........Los Angeles CA 90089I..555-1555I
|
231
|
+
I..Average Joe.......................I..EngineeringI...Somewhere over the rainbowI.......N/AI
|
232
|
+
I..1.................................I.............I.............................I..........I
|
233
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
234
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
235
|
+
I..홍길동............................I.............I..서울역 3번 출구 김씨 옆자리I..........I
|
236
|
+
I....................................I.............I.............................I.......N/AI
|
237
|
+
I....................................I...탁상 3부..I.....................맞습니다I..........I
|
238
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
239
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
240
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
241
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#
|
242
|
+
I..This should change everything doh!I.............I.............................I..........I
|
243
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#".strip
|
244
|
+
assert_equal output, table.to_s.strip
|
194
245
|
assert_equal output, table.to_s.strip
|
246
|
+
|
247
|
+
separator = '#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#~~~~~~~~~~#'
|
248
|
+
line = 'I..a.................................I.......b.....I............................cI.........dI'
|
249
|
+
10.times do |i|
|
250
|
+
table << %w[a b c d]
|
251
|
+
expected = (output.lines.to_a[0..-2].map(&:chomp) + [line] * (i+1) + [separator]).join($/)
|
252
|
+
assert_equal expected, table.to_s
|
253
|
+
end
|
195
254
|
end
|
196
255
|
|
197
256
|
def test_screen_width
|
198
257
|
[1, 3, 9, 50, 80].each do |w|
|
199
258
|
t = Tabularize.new :screen_width => w
|
200
259
|
10.times do
|
201
|
-
t << ['12345'] *
|
260
|
+
t << ['12345'] * 20
|
202
261
|
end
|
203
|
-
puts t
|
204
262
|
assert t.to_s.lines.all? { |line| line.chomp.length <= w }
|
263
|
+
t << %w[12345]
|
264
|
+
puts t.to_s
|
265
|
+
assert t.to_s.lines.all? { |line| line.chomp.length <= w }
|
266
|
+
assert t.to_s.lines.all? { |line| %w[+ >].include?(line.chomp.reverse[0, 1]) }
|
205
267
|
end
|
206
268
|
end
|
207
269
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabularize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|
@@ -76,11 +76,12 @@ files:
|
|
76
76
|
- lib/tabularize.rb
|
77
77
|
- lib/tabularize/version.rb
|
78
78
|
- tabularize.gemspec
|
79
|
+
- test/fixture/tabularize_csv.txt
|
80
|
+
- test/fixture/test.csv
|
81
|
+
- test/fixture/test_unicode.csv
|
82
|
+
- test/fixture/test_unicode_ansi.csv
|
79
83
|
- test/readme.rb
|
80
|
-
- test/test.csv
|
81
84
|
- test/test_tabularize.rb
|
82
|
-
- test/test_unicode.csv
|
83
|
-
- test/test_unicode_ansi.csv
|
84
85
|
homepage: ''
|
85
86
|
licenses: []
|
86
87
|
post_install_message:
|
@@ -106,8 +107,9 @@ signing_key:
|
|
106
107
|
specification_version: 3
|
107
108
|
summary: Formatting tabular data
|
108
109
|
test_files:
|
110
|
+
- test/fixture/tabularize_csv.txt
|
111
|
+
- test/fixture/test.csv
|
112
|
+
- test/fixture/test_unicode.csv
|
113
|
+
- test/fixture/test_unicode_ansi.csv
|
109
114
|
- test/readme.rb
|
110
|
-
- test/test.csv
|
111
115
|
- test/test_tabularize.rb
|
112
|
-
- test/test_unicode.csv
|
113
|
-
- test/test_unicode_ansi.csv
|