tabulate 0.1.1 → 0.1.2
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/lib/tabulate.rb +19 -17
- data/version.txt +1 -1
- metadata +36 -30
data/lib/tabulate.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# * :hrframe: heading right frame
|
17
17
|
# * :padding: number of padding characters for each field on each side
|
18
18
|
#
|
19
|
-
$
|
19
|
+
$table_template = {
|
20
20
|
"simple" => {
|
21
21
|
:rs => '', :fs => ' | ', :cross => '+',
|
22
22
|
:lframe => '', :rframe => '' ,
|
@@ -78,11 +78,13 @@ def tabulate(labels, data, opts = { } )
|
|
78
78
|
opts = { :indent => 0, :style => 'fancy'}.merge opts
|
79
79
|
indent = opts[:indent]
|
80
80
|
style = opts[:style]
|
81
|
-
raise "Invalid table style!" unless $
|
81
|
+
raise "Invalid table style!" unless $table_template.keys.include? style
|
82
|
+
|
83
|
+
style = $table_template[style]
|
82
84
|
|
83
85
|
data = data.inject([]){|rs, r| rs += r.to_rows }
|
84
86
|
data = data.unshift(labels).transpose
|
85
|
-
padding =
|
87
|
+
padding = style[:padding]
|
86
88
|
data = data.collect {|c|
|
87
89
|
c.collect {|e| ' ' * padding + e.to_s + ' ' * padding }
|
88
90
|
}
|
@@ -93,37 +95,37 @@ def tabulate(labels, data, opts = { } )
|
|
93
95
|
}
|
94
96
|
data = newdata
|
95
97
|
data = data.transpose
|
96
|
-
data = [
|
97
|
-
data[1..-1].collect {|l|
|
98
|
+
data = [ style[:hlframe] + data[0].join(style[:fs]) + style[:hrframe] ] + \
|
99
|
+
data[1..-1].collect {|l| style[:lframe] + l.join(style[:fs]) + style[:rframe] }
|
98
100
|
lines = []
|
99
101
|
|
100
102
|
#add top frame
|
101
|
-
if
|
102
|
-
lines <<
|
103
|
+
if !style[:tframe].to_s.empty?
|
104
|
+
lines << style[:cross] + widths.collect{|n| style[:tframe] *n }.join(style[:cross]) + style[:cross]
|
103
105
|
end
|
104
106
|
|
105
107
|
#add title
|
106
108
|
lines << data[0]
|
107
109
|
|
108
110
|
#add title ruler
|
109
|
-
if
|
110
|
-
lines <<
|
111
|
-
elsif
|
112
|
-
lines << widths.collect{|n|
|
111
|
+
if !style[:hs].to_s.empty? and !style[:lframe].to_s.empty?
|
112
|
+
lines << style[:cross] + widths.collect{|n| style[:hs] *n }.join(style[:cross]) + style[:cross]
|
113
|
+
elsif !style[:hs].to_s.empty?
|
114
|
+
lines << widths.collect{|n| style[:hs] *n }.join(style[:cross])
|
113
115
|
end
|
114
116
|
|
115
117
|
#add data
|
116
118
|
data[1..-2].each{ |line|
|
117
119
|
lines << line
|
118
|
-
if
|
119
|
-
lines <<
|
120
|
+
if !style[:rs].to_s.empty?
|
121
|
+
lines << style[:cross] + widths.collect{|n| style[:rs] *n }.join(style[:cross]) + style[:cross]
|
120
122
|
end
|
121
123
|
}
|
122
124
|
|
123
125
|
#add last record and bottom frame
|
124
126
|
lines << data[-1]
|
125
|
-
if
|
126
|
-
lines <<
|
127
|
+
if !style[:bframe].to_s.empty?
|
128
|
+
lines << style[:cross] + widths.collect{|n| style[:bframe] *n }.join(style[:cross]) + style[:cross]
|
127
129
|
end
|
128
130
|
|
129
131
|
#add indent
|
@@ -163,8 +165,8 @@ end
|
|
163
165
|
if __FILE__ == $0
|
164
166
|
source = [["\e[31maht\e[m",3],[4,"\e[33msomething\e[m"],['s',['abc','de']]]
|
165
167
|
labels = ["a",'b']
|
166
|
-
puts "Available themes: #{$
|
167
|
-
$
|
168
|
+
puts "Available themes: #{$table_template.keys.inspect}"
|
169
|
+
$table_template.keys.each do |k|
|
168
170
|
puts "#{k} :"
|
169
171
|
puts tabulate(labels, source, :indent => 4, :style => k)
|
170
172
|
puts
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
metadata
CHANGED
@@ -1,36 +1,39 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabulate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Roy Zuo (aka roylez)
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-05-19 00:00:00 +08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
15
17
|
name: bones
|
16
|
-
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
20
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
21
24
|
version: 3.6.5
|
22
25
|
type: :development
|
23
|
-
|
24
|
-
version_requirements: *86175090
|
26
|
+
version_requirements: *id001
|
25
27
|
description: Create fancy command line tables with ease.
|
26
28
|
email: roylzuo AT gmail DOT com
|
27
|
-
executables:
|
29
|
+
executables:
|
28
30
|
- tabulate
|
29
31
|
extensions: []
|
30
|
-
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
31
34
|
- History.txt
|
32
35
|
- bin/tabulate
|
33
|
-
files:
|
36
|
+
files:
|
34
37
|
- .bnsignore
|
35
38
|
- History.txt
|
36
39
|
- README.md
|
@@ -41,31 +44,34 @@ files:
|
|
41
44
|
- spec/tabulate_spec.rb
|
42
45
|
- test/test_tabulate.rb
|
43
46
|
- version.txt
|
47
|
+
has_rdoc: true
|
44
48
|
homepage: http://tabulate.rubygems.org
|
45
49
|
licenses: []
|
50
|
+
|
46
51
|
post_install_message:
|
47
|
-
rdoc_options:
|
52
|
+
rdoc_options:
|
48
53
|
- --main
|
49
54
|
- README.md
|
50
|
-
require_paths:
|
55
|
+
require_paths:
|
51
56
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
58
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
64
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version:
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
64
69
|
requirements: []
|
70
|
+
|
65
71
|
rubyforge_project: tabulate
|
66
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.5.2
|
67
73
|
signing_key:
|
68
74
|
specification_version: 3
|
69
75
|
summary: Create fancy command line tables with ease.
|
70
|
-
test_files:
|
76
|
+
test_files:
|
71
77
|
- test/test_tabulate.rb
|