christiank-turntable 1.1.0 → 1.1.1

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 +45 -31
  2. metadata +1 -1
data/turntable.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Turntable v1.1.0
2
+ # Turntable
3
3
  # Christian Koch <ckoch002@student.ucr.edu>
4
4
  #
5
5
  # Turntable is an alternative relational database for Ruby. A Turntable object
@@ -13,7 +13,7 @@ require 'ostruct'
13
13
 
14
14
  class Turntable
15
15
 
16
- VERSION = 'v1.1.0'
16
+ VERSION = 'v1.1.1'
17
17
 
18
18
  include Enumerable
19
19
  def each
@@ -125,38 +125,13 @@ class Turntable
125
125
  @pushing = true
126
126
  self.update
127
127
  row
128
- end
129
-
130
- # Returns a string ready for HTML.
131
- def to_html
132
- string = "<table>\n"
133
-
134
- string += "\t<tr>\n"
135
- @table[:columns].each { |column| string += "\t\t<th>#{column}</th>\n" }
136
- string += "\t</tr>\n"
137
-
138
- self.each do |row|
139
- string += "\t<tr>\n"
140
- row.table.each_value { |value| string += "\t\t<td>#{value}</td>\n" }
141
- string += "\t</tr>\n"
142
- end
143
-
144
- string += '</table>'
145
128
  end
146
129
 
147
- # Returns a string ready for Textile.
148
- def to_textile
149
- string = ''
130
+ # Just a wrapper for Array#to_html.
131
+ def to_html; self.to_a.to_html; end
150
132
 
151
- @table[:columns].each { |column| string += "|_.#{column}" }
152
- string += "|\n"
153
- self.each do |row|
154
- row.table.each_value { |value| string += "|#{value}" }
155
- string += "|\n"
156
- end
157
-
158
- string
159
- end
133
+ # Just a wrapper for Array#to_textile.
134
+ def to_textile; self.to_a.to_textile; end
160
135
 
161
136
  # Any changes to the external file must occur within this block. If something
162
137
  # goes wrong (like trying to push a Proc object) then no changes are made.
@@ -188,6 +163,45 @@ class Row < OpenStruct
188
163
  public :table
189
164
  end
190
165
 
166
+ class Array
167
+
168
+ # Takes an array of Row objects and returns a HTML-table-fomatted string.
169
+ def to_html
170
+ string = "<table>\n"
171
+
172
+ string += "\t<tr>\n"
173
+ self.first.table.each_key { |column| string += "\t\t<th>#{column}</th>\n" }
174
+ string += "\t</tr>\n"
175
+
176
+ self.each do |row|
177
+ string += "\t<tr>\n"
178
+ row.table.each_value { |value| string += "\t\t<td>#{value}</td>\n" }
179
+ string += "\t</tr>\n"
180
+ end
181
+
182
+ string += '</table>'
183
+ end
184
+
185
+ # Writes the output of any query to STDOUT.
186
+ def to_stdout; puts self.to_textile; end
187
+
188
+ # Takes an array of Row objects and returns a Textile-table-formatted string.
189
+ # Could be used in conjunction with RedCloth.
190
+ def to_textile
191
+ string = ''
192
+
193
+ self.first.table.each_key { |column| string += "|_.#{column}" }
194
+ string += "|\n"
195
+ self.each do |row|
196
+ row.table.each_value { |value| string += "|#{value}" }
197
+ string += "|\n"
198
+ end
199
+
200
+ string
201
+ end
202
+
203
+ end
204
+
191
205
  class Object
192
206
 
193
207
  # Turn off Object#id warnings.
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Koch