tabulate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.bnsignore +18 -0
- data/History.txt +3 -1
- data/lib/tabulate.rb +30 -15
- data/version.txt +1 -1
- metadata +30 -49
data/.bnsignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
2
|
+
# Lines that start with '#' are comments.
|
3
|
+
#
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
+
# file in your Rakefile:
|
6
|
+
#
|
7
|
+
# Bones {
|
8
|
+
# ignore_file '.gitignore'
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# For a project with a C extension, the following would be a good set of
|
12
|
+
# exclude patterns (uncomment them if you want to use them):
|
13
|
+
# *.[oa]
|
14
|
+
# *~
|
15
|
+
announcement.txt
|
16
|
+
coverage
|
17
|
+
doc
|
18
|
+
pkg
|
data/History.txt
CHANGED
data/lib/tabulate.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
|
-
#
|
3
|
+
# A simple tabulate method to columnize data in console.
|
4
|
+
#
|
5
|
+
# author:: Roy Zuo (aka roylez)
|
6
|
+
#
|
4
7
|
|
8
|
+
# global template variable
|
9
|
+
# * :rs: record seperator
|
10
|
+
# * :hs: heading seperator
|
11
|
+
# * :fs: field seperator
|
12
|
+
# * :cross: the cross point of record seperator and field seperator
|
13
|
+
# * :lframe: left frame
|
14
|
+
# * :rframe: right frame
|
15
|
+
# * :hlframe: heading left frame
|
16
|
+
# * :hrframe: heading right frame
|
17
|
+
# * :padding: number of padding characters for each field on each side
|
18
|
+
#
|
5
19
|
$template = {
|
6
20
|
"simple" => {
|
7
21
|
:rs => '', :fs => ' | ', :cross => '+',
|
@@ -48,17 +62,16 @@ $template = {
|
|
48
62
|
},
|
49
63
|
}
|
50
64
|
|
51
|
-
# tabulate arrays,
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
65
|
+
# tabulate arrays, it accepts the following arguments
|
66
|
+
# * :label: table headings, an array
|
67
|
+
# * :data: table data. Each elements stands for one *or more* rows.
|
68
|
+
# For example, [[1, 2] , [3, [4, 5]], [nil, 6]] will be processed as 4 lines
|
69
|
+
# +1 2+
|
70
|
+
# +3 4+
|
71
|
+
# +3 5+
|
72
|
+
# + 6+
|
73
|
+
# * :opts: optional arguments, default to :indent => 0, :style => 'fancy'
|
57
74
|
# return a String
|
58
|
-
#
|
59
|
-
# [ [a, b, c], [d, e, [f, g]] .... ]
|
60
|
-
# [ a, b, c] will be used as a single row
|
61
|
-
# and [d, e,[f,g]] will be used as two rows
|
62
75
|
def tabulate(labels, data, opts = { } )
|
63
76
|
raise 'Label and data do not have equal columns!' unless labels.size == data.transpose.size
|
64
77
|
|
@@ -129,17 +142,19 @@ end
|
|
129
142
|
|
130
143
|
class String
|
131
144
|
if RUBY_VERSION >= '1.9'
|
145
|
+
# test if string contains east Asian character (RUBY_VERSION > 1.9)
|
132
146
|
def contains_cjk? # Oniguruma regex !!!
|
133
147
|
(self =~ /\p{Han}|\p{Katakana}|\p{Hiragana}\p{Hangul}/)
|
134
148
|
end
|
135
|
-
|
149
|
+
end
|
150
|
+
# actual string width
|
151
|
+
def width
|
152
|
+
if RUBY_VERSION >= '1.9'
|
136
153
|
gsub(/(\e|\033|\33)\[[;0-9]*\D/,'').split(//).inject( 0 ) do |s, i|
|
137
154
|
s += i.contains_cjk? ? 2 : 1
|
138
155
|
s
|
139
156
|
end
|
140
|
-
|
141
|
-
else
|
142
|
-
def width
|
157
|
+
else
|
143
158
|
gsub(/(\e|\033|\33)\[[;0-9]*\D/,'').size
|
144
159
|
end
|
145
160
|
end
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
metadata
CHANGED
@@ -1,48 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabulate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Roy Zuo (aka roylez)
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-04-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: bones
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &86175090 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 21
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 6
|
32
|
-
- 5
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 3.6.5
|
34
22
|
type: :development
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *86175090
|
36
25
|
description: Create fancy command line tables with ease.
|
37
26
|
email: roylzuo AT gmail DOT com
|
38
|
-
executables:
|
27
|
+
executables:
|
39
28
|
- tabulate
|
40
29
|
extensions: []
|
41
|
-
|
42
|
-
extra_rdoc_files:
|
30
|
+
extra_rdoc_files:
|
43
31
|
- History.txt
|
44
32
|
- bin/tabulate
|
45
|
-
files:
|
33
|
+
files:
|
34
|
+
- .bnsignore
|
46
35
|
- History.txt
|
47
36
|
- README.md
|
48
37
|
- Rakefile
|
@@ -54,37 +43,29 @@ files:
|
|
54
43
|
- version.txt
|
55
44
|
homepage: http://tabulate.rubygems.org
|
56
45
|
licenses: []
|
57
|
-
|
58
46
|
post_install_message:
|
59
|
-
rdoc_options:
|
47
|
+
rdoc_options:
|
60
48
|
- --main
|
61
49
|
- README.md
|
62
|
-
require_paths:
|
50
|
+
require_paths:
|
63
51
|
- lib
|
64
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
53
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
- 0
|
72
|
-
version: "0"
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
59
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
version: "0"
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
82
64
|
requirements: []
|
83
|
-
|
84
65
|
rubyforge_project: tabulate
|
85
66
|
rubygems_version: 1.7.2
|
86
67
|
signing_key:
|
87
68
|
specification_version: 3
|
88
69
|
summary: Create fancy command line tables with ease.
|
89
|
-
test_files:
|
70
|
+
test_files:
|
90
71
|
- test/test_tabulate.rb
|