panic_board_data 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/panic_board_data/graph.rb +1 -3
- data/lib/panic_board_data/table.rb +57 -26
- data/lib/panic_board_data/version.rb +1 -1
- data/spec/panic_board_data/table_spec.rb +96 -27
- metadata +4 -4
@@ -1,3 +1,4 @@
|
|
1
|
+
# http://www.panic.com/statusboard/docs/table_tutorial.pdf
|
1
2
|
require 'csv'
|
2
3
|
|
3
4
|
module PanicBoardData
|
@@ -5,37 +6,26 @@ module PanicBoardData
|
|
5
6
|
|
6
7
|
attr_accessor :data, :widths, :base_image_url
|
7
8
|
|
9
|
+
def initialize(data = [])
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
8
13
|
def build_image value
|
14
|
+
"<img src=\"#{url_for(value)}\" />"
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
.map
|
13
|
-
.
|
14
|
-
.join('/')
|
15
|
-
.gsub('http:', 'http://')
|
16
|
-
.gsub('https:', 'https://')
|
17
|
-
"<img src=\"#{url}\" />"
|
17
|
+
def progress_bar_to int
|
18
|
+
(1..int).to_a
|
19
|
+
.map { |x| "<div class=\"barSegment value#{x}\"></div>" }
|
20
|
+
.join
|
18
21
|
end
|
19
22
|
|
20
23
|
def to_html
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
record.each_with_index do |value, index|
|
27
|
-
value = value.join('') if value.is_a?(Array)
|
28
|
-
if widths && widths[index]
|
29
|
-
result << "<td style=\"width: #{widths[index]}px\">#{value}</td>"
|
30
|
-
else
|
31
|
-
result << "<td>#{value}</td>"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
result << "</tr>"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
result << "</table>"
|
24
|
+
"<table>#{data_to_table_rows}</table>"
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_csv
|
28
|
+
self.class.to_csv self.data
|
39
29
|
end
|
40
30
|
|
41
31
|
def self.to_csv data
|
@@ -43,5 +33,46 @@ module PanicBoardData
|
|
43
33
|
data.each { |row| csv << row }
|
44
34
|
end.strip
|
45
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def url_for value
|
40
|
+
[self.base_image_url, value]
|
41
|
+
.select { |x| x.to_s != '' }
|
42
|
+
.map { |x| x.to_s.strip }
|
43
|
+
.map { |x| x.gsub('/', '') }
|
44
|
+
.join('/')
|
45
|
+
.gsub('http:', 'http://')
|
46
|
+
.gsub('https:', 'https://')
|
47
|
+
end
|
48
|
+
|
49
|
+
def data_to_table_rows
|
50
|
+
return '' unless data
|
51
|
+
data.map { |r| build_row_for r }.join
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_row_for record
|
55
|
+
result = record.each_with_index.map { |v, i| build_cell_for v, i }.join
|
56
|
+
"<tr>#{result}</tr>"
|
57
|
+
end
|
58
|
+
|
59
|
+
def build_cell_for value, index
|
60
|
+
value = flatten_a_value_array_to_a_single_value value
|
61
|
+
width = get_width_for index
|
62
|
+
render_cell value, width
|
63
|
+
end
|
64
|
+
|
65
|
+
def flatten_a_value_array_to_a_single_value value
|
66
|
+
value.is_a?(Array) ? value.join('') : value
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_width_for index
|
70
|
+
widths ? widths[index] : nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_cell value, width
|
74
|
+
width ? "<td style=\"width: #{width}px\">#{value}</td>"
|
75
|
+
: "<td>#{value}</td>"
|
76
|
+
end
|
46
77
|
end
|
47
78
|
end
|
@@ -6,6 +6,20 @@ describe PanicBoardData::Table do
|
|
6
6
|
PanicBoardData::Table.new
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "initialize" do
|
10
|
+
|
11
|
+
it "should default data to an empty array" do
|
12
|
+
PanicBoardData::Table.new.data.count.must_equal 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow a new table to be built with data" do
|
16
|
+
data = Object.new
|
17
|
+
table = PanicBoardData::Table.new data
|
18
|
+
table.data.must_be_same_as data
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
9
23
|
describe "to_html" do
|
10
24
|
|
11
25
|
describe "empty table" do
|
@@ -36,7 +50,9 @@ describe PanicBoardData::Table do
|
|
36
50
|
it "should return a result" do
|
37
51
|
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
38
52
|
end
|
53
|
+
|
39
54
|
end
|
55
|
+
|
40
56
|
end
|
41
57
|
|
42
58
|
[:array, :first_width, :second_width, :result].to_objects { [
|
@@ -57,7 +73,9 @@ describe PanicBoardData::Table do
|
|
57
73
|
it "should return a result" do
|
58
74
|
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
59
75
|
end
|
76
|
+
|
60
77
|
end
|
78
|
+
|
61
79
|
end
|
62
80
|
|
63
81
|
[:array, :result].to_objects { [
|
@@ -76,7 +94,9 @@ describe PanicBoardData::Table do
|
|
76
94
|
it "should return a result" do
|
77
95
|
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
78
96
|
end
|
97
|
+
|
79
98
|
end
|
99
|
+
|
80
100
|
end
|
81
101
|
|
82
102
|
[:first_image, :second_image, :result].to_objects { [
|
@@ -94,7 +114,9 @@ describe PanicBoardData::Table do
|
|
94
114
|
it "should return a result" do
|
95
115
|
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
96
116
|
end
|
117
|
+
|
97
118
|
end
|
119
|
+
|
98
120
|
end
|
99
121
|
|
100
122
|
[:array, :base_image_url, :result].to_objects { [
|
@@ -118,49 +140,96 @@ describe PanicBoardData::Table do
|
|
118
140
|
it "should return a result" do
|
119
141
|
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
120
142
|
end
|
143
|
+
|
121
144
|
end
|
145
|
+
|
122
146
|
end
|
123
|
-
end
|
124
147
|
|
125
|
-
|
148
|
+
[:value, :result].to_objects {[
|
149
|
+
[1, '<div class="barSegment value1"></div>'],
|
150
|
+
[2, '<div class="barSegment value1"></div><div class="barSegment value2"></div>'],
|
151
|
+
[8, '<div class="barSegment value1"></div><div class="barSegment value2"></div><div class="barSegment value3"></div><div class="barSegment value4"></div><div class="barSegment value5"></div><div class="barSegment value6"></div><div class="barSegment value7"></div><div class="barSegment value8"></div>']
|
152
|
+
]}.each do |test|
|
126
153
|
|
127
|
-
|
128
|
-
|
129
|
-
|
154
|
+
describe "progress bars" do
|
155
|
+
|
156
|
+
before do
|
157
|
+
table.data = [['a', table.progress_bar_to(test.value)]]
|
130
158
|
|
131
|
-
|
132
|
-
|
159
|
+
@result = table.to_html
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should create a cell with the proper progress bar" do
|
163
|
+
@result.must_equal "<table><tr><td>a</td><td>#{test.result}</td></tr></table>"
|
164
|
+
end
|
133
165
|
|
134
|
-
it "should return an empty string" do
|
135
|
-
@result.must_equal ''
|
136
166
|
end
|
167
|
+
|
137
168
|
end
|
138
169
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
[->(d) { PanicBoardData::Table.to_csv(d) },
|
173
|
+
->(d) do
|
174
|
+
t = PanicBoardData::Table.new
|
175
|
+
t.data = d
|
176
|
+
t.to_csv
|
177
|
+
end
|
178
|
+
].each do |method|
|
179
|
+
|
180
|
+
describe "to_csv" do
|
181
|
+
|
182
|
+
before do
|
183
|
+
@result = method.call(data)
|
184
|
+
end
|
147
185
|
|
148
|
-
|
149
|
-
|
186
|
+
describe "an empty set" do
|
187
|
+
|
188
|
+
let(:data) { [] }
|
189
|
+
|
190
|
+
it "should return an empty string" do
|
191
|
+
@result.must_equal ''
|
150
192
|
end
|
193
|
+
|
151
194
|
end
|
152
|
-
end
|
153
195
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
196
|
+
[:array, :result].to_objects { [
|
197
|
+
[ [0], "0" ],
|
198
|
+
[ [1], "1" ],
|
199
|
+
[ [1,2], "1,2" ],
|
200
|
+
[ [3,4, '"'], "3,4,\"\"\"\"" ]
|
201
|
+
] }.each do |test|
|
202
|
+
|
203
|
+
describe "one row" do
|
204
|
+
|
205
|
+
let(:data) { [ test.array ] }
|
206
|
+
|
207
|
+
it "should return the single value" do
|
208
|
+
@result.must_equal test.result
|
209
|
+
end
|
159
210
|
|
160
|
-
it "should return the single value" do
|
161
|
-
@result.must_equal test.result
|
162
211
|
end
|
212
|
+
|
163
213
|
end
|
214
|
+
|
215
|
+
[:first_row, :second_row, :result].to_objects { [
|
216
|
+
[ [0], [1], "0\n1" ],
|
217
|
+
] }.each do |test|
|
218
|
+
|
219
|
+
describe "two rows" do
|
220
|
+
|
221
|
+
let(:data) { [ test.first_row, test.second_row ] }
|
222
|
+
|
223
|
+
it "should return the single value" do
|
224
|
+
@result.must_equal test.result
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
164
231
|
end
|
232
|
+
|
165
233
|
end
|
234
|
+
|
166
235
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panic_board_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: -716652775732069663
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
segments:
|
154
154
|
- 0
|
155
|
-
hash:
|
155
|
+
hash: -716652775732069663
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
158
|
rubygems_version: 1.8.25
|