table_print 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/features/multibyte.feature +1 -0
- data/features/printing_struct.feature +1 -1
- data/features/support/step_definitions/steps.rb +6 -6
- data/lib/table_print/column.rb +15 -4
- data/lib/table_print/config.rb +9 -0
- data/lib/table_print/formatter.rb +9 -1
- data/lib/table_print/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWE4N2E1NDljNGIwMDVkMjBkZWM2ZmRmNDlhZjBiYWQzOTQ4ZTZiOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzI3NTg0NGNmNjg2Y2Q4NGE4MWIzNzZjNmVkY2Y1YWI1YjBhOTJkZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2I2NDQyM2NjZDVkZDkzNzNkNmE1NTM5ODM5NDE1NDYzYzU0OGEwMjM0NmUy
|
10
|
+
N2EzM2M5YWFmYTE2ZDM2Njc1ZGU1OWQxYjJhNGI1NWE2MmNlYWVkYWY1NmMz
|
11
|
+
OTA2NjY2Mzk0MTZkNmM3M2M1ZDQwZGFhYzY1ZTJlZDEzNTUyNjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmYzZWNmNjEwMGZkYTI2NGQ1MzY0ZDFlODBlNGQwMjk5YTEyYzgyMmQ4YzM5
|
14
|
+
ZWNlYmE1Y2EyYTRhNzg2ZGU2MzY4ZDM0NWU4ZGJlZWQ3Yjg0ODM3MzU4ODJm
|
15
|
+
NGVhYmYxY2M5YmE5NzAxMzNkODc1MjlkN2ZlZjE4Zjc4OWE1Yzg=
|
data/features/multibyte.feature
CHANGED
@@ -58,6 +58,10 @@ When /^I instantiate a (.*) with (\{.*\}) and (add it|assign it) to (.*)$/ do |k
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
When /^I configure multibyte with (.*)$/ do |value|
|
62
|
+
TablePrint::Config.set(:multibyte, [value == "true"])
|
63
|
+
end
|
64
|
+
|
61
65
|
When /^configure (.*) with (.*)$/ do |klass, config|
|
62
66
|
klass = Sandbox.const_get_from_string(klass)
|
63
67
|
TablePrint::Config.set(klass, eval(config))
|
@@ -70,16 +74,12 @@ end
|
|
70
74
|
When /table_print ([\w\.:]*)$/ do |klass|
|
71
75
|
obj = @objs.send(klass.split(".").first.downcase)
|
72
76
|
obj = obj.send(klass.split(".").last) if klass.include? "." # hack - we're assuming only two levels. use inject to find the target.
|
73
|
-
|
77
|
+
|
74
78
|
tp(obj)
|
75
79
|
end
|
76
80
|
|
77
81
|
Then /^the output should contain$/ do |string|
|
78
|
-
output =
|
79
|
-
while line = @r.gets
|
80
|
-
output << line
|
81
|
-
end
|
82
|
-
@r.close
|
82
|
+
output = @r.lines.to_a
|
83
83
|
|
84
84
|
output.zip(string.split("\n")).each do |actual, expected|
|
85
85
|
actual.gsub(/\s/m, "").split(//).sort.join.should == expected.gsub(" ", "").split(//).sort.join
|
data/lib/table_print/column.rb
CHANGED
@@ -34,10 +34,17 @@ module TablePrint
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def data_width
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if multibyte_count
|
38
|
+
[
|
39
|
+
name.each_char.collect{|c| c.bytesize == 1 ? 1 : 2}.inject(0, &:+),
|
40
|
+
Array(data).compact.collect(&:to_s).collect{|m| m.each_char.collect{|n| n.bytesize == 1 ? 1 : 2}.inject(0, &:+)}.max
|
41
|
+
].compact.max || 0
|
42
|
+
else
|
43
|
+
[
|
44
|
+
name.length,
|
45
|
+
Array(data).compact.collect(&:to_s).collect(&:length).max
|
46
|
+
].compact.max || 0
|
47
|
+
end
|
41
48
|
end
|
42
49
|
|
43
50
|
def width
|
@@ -48,5 +55,9 @@ module TablePrint
|
|
48
55
|
def max_width
|
49
56
|
TablePrint::Config.max_width
|
50
57
|
end
|
58
|
+
|
59
|
+
def multibyte_count
|
60
|
+
TablePrint::Config.multibyte
|
61
|
+
end
|
51
62
|
end
|
52
63
|
end
|
data/lib/table_print/config.rb
CHANGED
@@ -6,6 +6,7 @@ module TablePrint
|
|
6
6
|
|
7
7
|
@@max_width = DEFAULT_MAX_WIDTH
|
8
8
|
@@time_format = DEFAULT_TIME_FORMAT
|
9
|
+
@@multibyte = false
|
9
10
|
|
10
11
|
@@klasses = {}
|
11
12
|
|
@@ -38,6 +39,14 @@ module TablePrint
|
|
38
39
|
@@max_width = width
|
39
40
|
end
|
40
41
|
|
42
|
+
def self.multibyte
|
43
|
+
@@multibyte
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.multibyte=(width)
|
47
|
+
@@multibyte = width
|
48
|
+
end
|
49
|
+
|
41
50
|
def self.time_format
|
42
51
|
@@time_format
|
43
52
|
end
|
@@ -25,7 +25,7 @@ module TablePrint
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def format(value)
|
28
|
-
padding = width - value.to_s
|
28
|
+
padding = width - length(value.to_s)
|
29
29
|
truncate(value) + (padding < 0 ? '' : " " * padding)
|
30
30
|
end
|
31
31
|
|
@@ -38,5 +38,13 @@ module TablePrint
|
|
38
38
|
|
39
39
|
"#{value[0..width-4]}..."
|
40
40
|
end
|
41
|
+
|
42
|
+
def length(str)
|
43
|
+
if TablePrint::Config.multibyte
|
44
|
+
str.each_char.collect{|c| c.bytesize == 1 ? 1 : 2}.inject(0, &:+)
|
45
|
+
else
|
46
|
+
str.length
|
47
|
+
end
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
data/lib/table_print/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_print
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cat
|