dashes 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dashes.rb +7 -21
- metadata +2 -2
data/lib/dashes.rb
CHANGED
@@ -1,18 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
module Dashes
|
4
|
-
VERSION = '0.0.
|
5
|
-
|
6
|
-
def self.clean(str)
|
7
|
-
str.to_s.
|
8
|
-
gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
|
9
|
-
gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
|
10
|
-
gsub(/(\x03|\x1a)/, '')
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.strlen(str)
|
14
|
-
str.nil? ? 0 : clean(str).length
|
15
|
-
end
|
4
|
+
VERSION = '0.0.3'
|
16
5
|
|
17
6
|
class Node
|
18
7
|
def width(width); raise NotImplementedError; end
|
@@ -23,7 +12,7 @@ module Dashes
|
|
23
12
|
private
|
24
13
|
def cell(data, width, align=:left)
|
25
14
|
str = data.to_s
|
26
|
-
length =
|
15
|
+
length = str.length
|
27
16
|
if length > width
|
28
17
|
str[0...width]
|
29
18
|
elsif align == :center
|
@@ -119,7 +108,7 @@ module Dashes
|
|
119
108
|
widths = [0] * cols
|
120
109
|
(0...cols).map do |col|
|
121
110
|
@rows.each do |row|
|
122
|
-
widths[col] = [
|
111
|
+
widths[col] = [row[col].length, widths[col]].max
|
123
112
|
end
|
124
113
|
end
|
125
114
|
pad = (2 * cols) + (cols + 1) # cell padding/borders
|
@@ -214,11 +203,11 @@ module Dashes
|
|
214
203
|
end
|
215
204
|
|
216
205
|
def label_width
|
217
|
-
@rows.map { |row|
|
206
|
+
@rows.map { |row| row[0].length }.max
|
218
207
|
end
|
219
208
|
|
220
209
|
def title_width
|
221
|
-
|
210
|
+
@title.to_s.length
|
222
211
|
end
|
223
212
|
end
|
224
213
|
|
@@ -248,16 +237,13 @@ module Dashes
|
|
248
237
|
node.width(node_width)
|
249
238
|
if (index = buffer.index { |l| l.include?(space_matcher) })
|
250
239
|
# there's space for the table in a row, fit it in
|
251
|
-
col =
|
240
|
+
col = buffer[index] =~ Regexp.new(space_matcher)
|
252
241
|
node.to_s.split("\n").each do |line|
|
253
242
|
if buffer[index].nil?
|
254
243
|
buffer[index] = "#{" "*@width}"
|
255
244
|
end
|
256
245
|
new_line = col == 0 ? "#{line} " : " #{line}"
|
257
|
-
|
258
|
-
pre_line = buffer[index].split(space_matcher).first.to_s
|
259
|
-
offset = pre_line.length - Dashes.clean(pre_line).length
|
260
|
-
buffer[index][col+offset..(col+node_width+offset)] = new_line
|
246
|
+
buffer[index][col..(col+node_width)] = new_line
|
261
247
|
index += 1
|
262
248
|
end
|
263
249
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dashes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|