panic_board_data 0.0.7 → 0.0.8
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.
@@ -3,7 +3,19 @@ require 'csv'
|
|
3
3
|
module PanicBoardData
|
4
4
|
class Table
|
5
5
|
|
6
|
-
attr_accessor :data, :widths
|
6
|
+
attr_accessor :data, :widths, :base_image_url
|
7
|
+
|
8
|
+
def build_image value
|
9
|
+
|
10
|
+
url = [self.base_image_url, value]
|
11
|
+
.select { |x| x.to_s != '' }
|
12
|
+
.map { |x| x.to_s.strip }
|
13
|
+
.map { |x| x.gsub('/', '') }
|
14
|
+
.join('/')
|
15
|
+
.gsub('http:', 'http://')
|
16
|
+
.gsub('https:', 'https://')
|
17
|
+
"<img src=\"#{url}\" />"
|
18
|
+
end
|
7
19
|
|
8
20
|
def to_html
|
9
21
|
result = "<table>"
|
@@ -11,11 +23,12 @@ module PanicBoardData
|
|
11
23
|
if data
|
12
24
|
data.each do |record|
|
13
25
|
result << "<tr>"
|
14
|
-
record.each_with_index do |
|
26
|
+
record.each_with_index do |value, index|
|
27
|
+
value = value.join('') if value.is_a?(Array)
|
15
28
|
if widths && widths[index]
|
16
|
-
result << "<td style=\"width: #{widths[index]}px\">#{
|
29
|
+
result << "<td style=\"width: #{widths[index]}px\">#{value}</td>"
|
17
30
|
else
|
18
|
-
result << "<td>#{
|
31
|
+
result << "<td>#{value}</td>"
|
19
32
|
end
|
20
33
|
end
|
21
34
|
result << "</tr>"
|
@@ -60,6 +60,66 @@ describe PanicBoardData::Table do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
[:array, :result].to_objects { [
|
64
|
+
[ [0], "<td><img src=\"0\" /></td>"],
|
65
|
+
[ [1], "<td><img src=\"1\" /></td>"],
|
66
|
+
[ ['apple.jpg'], "<td><img src=\"apple.jpg\" /></td>"],
|
67
|
+
] }.each do |test|
|
68
|
+
|
69
|
+
describe "basic image use" do
|
70
|
+
|
71
|
+
before do
|
72
|
+
table.data = [test.array.map { |x| table.build_image x }]
|
73
|
+
@result = table.to_html
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return a result" do
|
77
|
+
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
[:first_image, :second_image, :result].to_objects { [
|
83
|
+
[ 0, 1, "<td><img src=\"0\" /><img src=\"1\" /></td>"],
|
84
|
+
[ 1, 2, "<td><img src=\"1\" /><img src=\"2\" /></td>"],
|
85
|
+
] }.each do |test|
|
86
|
+
|
87
|
+
describe "stacking multiple images into a single cell" do
|
88
|
+
|
89
|
+
before do
|
90
|
+
table.data = [[[table.build_image(test.first_image), table.build_image(test.second_image)]]]
|
91
|
+
@result = table.to_html
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return a result" do
|
95
|
+
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
[:array, :base_image_url, :result].to_objects { [
|
101
|
+
[ [0], "http://www.google.com", "<td><img src=\"http://www.google.com/0\" /></td>"],
|
102
|
+
[ [1], "http://www.bing.com/", "<td><img src=\"http://www.bing.com/1\" /></td>"],
|
103
|
+
[ ['apple.jpg'], nil, "<td><img src=\"apple.jpg\" /></td>"],
|
104
|
+
[ ['apple.jpg'], '', "<td><img src=\"apple.jpg\" /></td>"],
|
105
|
+
[ ['/apple.jpg'], 'http://www.bing.com/', "<td><img src=\"http://www.bing.com/apple.jpg\" /></td>"],
|
106
|
+
[ ['/apple.jpg'], 'https://www.bing.com/', "<td><img src=\"https://www.bing.com/apple.jpg\" /></td>"],
|
107
|
+
] }.each do |test|
|
108
|
+
|
109
|
+
describe "basic image use" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
table.base_image_url = test.base_image_url
|
113
|
+
table.data = [test.array.map { |x| table.build_image x }]
|
114
|
+
|
115
|
+
@result = table.to_html
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return a result" do
|
119
|
+
@result.must_equal "<table><tr>#{test.result}</tr></table>"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
63
123
|
end
|
64
124
|
|
65
125
|
describe "to_csv" do
|
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -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: 458088160656310672
|
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: 458088160656310672
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
158
|
rubygems_version: 1.8.25
|