ztk 1.4.9 → 1.4.10

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/ztk/report.rb +36 -31
  2. data/lib/ztk/version.rb +1 -1
  3. metadata +3 -3
data/lib/ztk/report.rb CHANGED
@@ -58,34 +58,35 @@ module ZTK
58
58
  else
59
59
  rows << block.call(dataset)
60
60
  end
61
+ rows.compact!
61
62
 
62
- max_lengths = max_spreadsheet_lengths(headers, rows)
63
- header_line = headers.collect { |header| "%-#{max_lengths.send(header)}s" % header.to_s.upcase }
64
- header_line = format_row(header_line)
63
+ if rows.count > 0
64
+ max_lengths = max_spreadsheet_lengths(headers, rows)
65
+ header_line = headers.collect { |header| "%-#{max_lengths.send(header)}s" % header.to_s.upcase }
66
+ header_line = format_row(header_line)
65
67
 
66
- config.ui.stdout.puts(format_header(headers, max_lengths))
67
- config.ui.stdout.puts(header_line)
68
- config.ui.stdout.puts(format_header(headers, max_lengths))
68
+ config.ui.stdout.puts(format_header(headers, max_lengths))
69
+ config.ui.stdout.puts(header_line)
70
+ config.ui.stdout.puts(format_header(headers, max_lengths))
69
71
 
70
- rows.each do |row|
71
- row_line = headers.collect do |header|
72
- header_length = max_lengths.send(header)
73
- content = row.send(header)
72
+ rows.each do |row|
73
+ row_line = headers.collect do |header|
74
+ header_length = max_lengths.send(header)
75
+ content = row.send(header)
74
76
 
75
- "%-#{header_length}s" % content
77
+ "%-#{header_length}s" % content
78
+ end
79
+
80
+ row_line = format_row(row_line)
81
+ config.ui.stdout.puts(row_line)
76
82
  end
77
83
 
78
- row_line = format_row(row_line)
79
- config.ui.stdout.puts(row_line)
84
+ config.ui.stdout.puts(format_header(headers, max_lengths))
85
+ OpenStruct.new(:rows => rows, :max_lengths => max_lengths, :width => calculate_spreadsheet_width(headers, max_lengths))
86
+ else
87
+ OpenStruct.new(:rows => rows, :max_lengths => 0, :width => 0)
80
88
  end
81
89
 
82
- config.ui.stdout.puts(format_header(headers, max_lengths))
83
-
84
- OpenStruct.new(
85
- :rows => rows,
86
- :max_lengths => max_lengths,
87
- :width => calculate_spreadsheet_width(headers, max_lengths)
88
- )
89
90
  end
90
91
 
91
92
  # Displays data in a key-value list style.
@@ -123,22 +124,26 @@ module ZTK
123
124
  else
124
125
  rows << block.call(dataset)
125
126
  end
127
+ rows.compact!
126
128
 
127
- max_key_length = headers.collect{ |header| header.length }.max
128
- max_value_length = rows.collect{ |row| headers.collect{ |header| row.send(header).to_s.length }.max }.max
129
+ if rows.count > 0
130
+ max_key_length = headers.collect{ |header| header.length }.max
131
+ max_value_length = rows.collect{ |row| headers.collect{ |header| row.send(header).to_s.length }.max }.max
129
132
 
130
- width = (max_key_length + max_value_length + 2 + 2 + 2)
133
+ width = (max_key_length + max_value_length + 2 + 2 + 2)
131
134
 
132
- rows.each do |row|
133
- config.ui.stdout.puts("+#{"-" * width}+")
134
- headers.each do |header|
135
- entry_line = format_entry(header, max_key_length, row.send(header), max_value_length)
136
- config.ui.stdout.puts(entry_line)
135
+ rows.each do |row|
136
+ config.ui.stdout.puts("+#{"-" * width}+")
137
+ headers.each do |header|
138
+ entry_line = format_entry(header, max_key_length, row.send(header), max_value_length)
139
+ config.ui.stdout.puts(entry_line)
140
+ end
137
141
  end
142
+ config.ui.stdout.puts("+#{"-" * width}+")
143
+ OpenStruct.new(:rows => rows, :max_key_length => max_key_length, :max_value_length => max_value_length, :width => width)
144
+ else
145
+ OpenStruct.new(:rows => rows, :max_key_length => 0, :max_value_length => 0, :width => 0)
138
146
  end
139
- config.ui.stdout.puts("+#{"-" * width}+")
140
-
141
- OpenStruct.new(:rows => rows, :max_key_length => max_key_length, :max_value_length => max_value_length, :width => width)
142
147
  end
143
148
 
144
149
 
data/lib/ztk/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module ZTK
2
2
 
3
3
  # ZTK Version String
4
- VERSION = "1.4.9"
4
+ VERSION = "1.4.10"
5
5
 
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.4.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -265,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
265
  version: '0'
266
266
  segments:
267
267
  - 0
268
- hash: 2449655142974466757
268
+ hash: 3276748823603867943
269
269
  required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  none: false
271
271
  requirements:
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  version: '0'
275
275
  segments:
276
276
  - 0
277
- hash: 2449655142974466757
277
+ hash: 3276748823603867943
278
278
  requirements: []
279
279
  rubyforge_project:
280
280
  rubygems_version: 1.8.25