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.
Files changed (2) hide show
  1. data/turntable.rb +31 -7
  2. metadata +1 -1
data/turntable.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # turntable v0.6.4.2
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.2'
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.first.table.each_key { |column| print "|_.#{column}" }
140
- puts '|'
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| print "|#{value}" }
143
- puts '|'
165
+ row.table.each_value { |value| string += "|#{value}" }
166
+ string += "|\n"
144
167
  end
145
- nil
168
+
169
+ string
146
170
  end
147
171
 
148
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: christiank-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4.2
4
+ version: 0.6.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Koch