christiank-turntable 0.6.4.2 → 0.6.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/turntable.rb +31 -7
- metadata +1 -1
data/turntable.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# turntable v0.6.4.
|
2
|
+
# turntable v0.6.4.3
|
3
3
|
# Christian Koch <ckoch002@student.ucr.edu>
|
4
4
|
#
|
5
5
|
|
@@ -8,7 +8,7 @@ require 'ostruct'
|
|
8
8
|
|
9
9
|
class Turntable < Array
|
10
10
|
|
11
|
-
@@version = 'v0.6.4.
|
11
|
+
@@version = 'v0.6.4.3'
|
12
12
|
|
13
13
|
@@insert_proc = %q(
|
14
14
|
if args.length != @columns.length
|
@@ -134,15 +134,39 @@ end
|
|
134
134
|
|
135
135
|
class Array
|
136
136
|
|
137
|
+
# Returns an array of rows in a HTML-formatted table.
|
138
|
+
def to_html
|
139
|
+
string = '<table>'
|
140
|
+
|
141
|
+
string += '<tr>'
|
142
|
+
self.first.table.each_key { |column| string += "<th>#{column}</th>" }
|
143
|
+
string += '</tr>'
|
144
|
+
|
145
|
+
self.each do |row|
|
146
|
+
string += '<tr>'
|
147
|
+
row.table.each_value { |value| string += "<td>#{value}</td>" }
|
148
|
+
string += '</tr>'
|
149
|
+
end
|
150
|
+
string += '</table>'
|
151
|
+
end
|
152
|
+
|
137
153
|
# Prints an array of rows to STDOUT.
|
138
154
|
def to_stdout
|
139
|
-
self.
|
140
|
-
|
155
|
+
puts self.to_textile
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns an array of rows in a Textile-formatted table.
|
159
|
+
def to_textile
|
160
|
+
string = ''
|
161
|
+
|
162
|
+
self.first.table.each_key { |column| string += "|_.#{column}" }
|
163
|
+
string += "|\n"
|
141
164
|
self.each do |row|
|
142
|
-
row.table.each_value { |value|
|
143
|
-
|
165
|
+
row.table.each_value { |value| string += "|#{value}" }
|
166
|
+
string += "|\n"
|
144
167
|
end
|
145
|
-
|
168
|
+
|
169
|
+
string
|
146
170
|
end
|
147
171
|
|
148
172
|
end
|