tabulate 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/tabulate.rb +19 -17
  2. data/version.txt +1 -1
  3. metadata +36 -30
@@ -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
- $template = {
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 $template.keys.include? style
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 = $template[style][: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 = [ $template[style][:hlframe] + data[0].join($template[style][:fs]) + $template[style][:hrframe] ] + \
97
- data[1..-1].collect {|l| $template[style][:lframe] + l.join($template[style][:fs]) + $template[style][:rframe] }
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 !$template[style][:tframe].to_s.empty?
102
- lines << $template[style][:cross] + widths.collect{|n| $template[style][:tframe] *n }.join($template[style][:cross]) + $template[style][:cross]
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 !$template[style][:hs].to_s.empty? and !$template[style][:lframe].to_s.empty?
110
- lines << $template[style][:cross] + widths.collect{|n| $template[style][:hs] *n }.join($template[style][:cross]) + $template[style][:cross]
111
- elsif !$template[style][:hs].to_s.empty?
112
- lines << widths.collect{|n| $template[style][:hs] *n }.join($template[style][:cross])
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 !$template[style][:rs].to_s.empty?
119
- lines << $template[style][:cross] + widths.collect{|n| $template[style][:rs] *n }.join($template[style][:cross]) + $template[style][:cross]
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 !$template[style][:bframe].to_s.empty?
126
- lines << $template[style][:cross] + widths.collect{|n| $template[style][:bframe] *n }.join($template[style][:cross]) + $template[style][:cross]
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: #{$template.keys.inspect}"
167
- $template.keys.each do |k|
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
@@ -1 +1 @@
1
- 0.1.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
- date: 2011-04-25 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
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
- requirement: &86175090 !ruby/object:Gem::Requirement
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
- prerelease: false
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
- extra_rdoc_files:
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: '0'
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: '0'
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
64
69
  requirements: []
70
+
65
71
  rubyforge_project: tabulate
66
- rubygems_version: 1.7.2
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