ruport 0.2.5 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,43 @@
1
- The current version of Ruby Reports is 0.2.5
1
+ The current version of Ruby Reports is 0.2.9
2
+
3
+ changes since Ruport 0.2.5:
4
+
5
+ - Added a new examples package with a 666 line walkthrough and more enjoyable
6
+ demonstratons
7
+
8
+ - Added support for multiple DSN's via add_dsn and select_dsn
9
+
10
+ - Added Tagging support for DataSets.
11
+
12
+ - Added DataSet#select_field and DataSet#select_fields to simplify grabbing
13
+ data by column
14
+
15
+ - Report::DataSet now implements to_s, for pretty printing goodness.
16
+
17
+ - render_text now implemented in Format::Builder
18
+
19
+ - Format::Builder now accepts headers and footers.
20
+
21
+ - Format::Builder now can generate complete html via output_type
22
+
23
+ - Ruport now uses FasterCSV, which is now a dependency. Yay! Dependencies!
24
+ (But it IS 9x faster than the CSV lib that ships with Ruby)
25
+
26
+ - Added tests to the gem spec... so you can use -t now.
27
+
28
+ - DataRow#+ implemented.
29
+
30
+ - Format::Builder#range implemented. (Can now format partial DataSets)
31
+
32
+ - Fixed a bug in the unit tests that required Ruport to be installed.
33
+ Now you can test BEFORE you install. (Sorry about that one...)
34
+
35
+ - Commands that return no rows no longer crash the application
36
+ (But writing to the database is still not fun nor easy)
37
+
38
+ - templates/ folder now more aptly named scripts/
39
+
40
+ - Report::Engine#query now returns a DataSet so chaining is possible
2
41
 
3
42
  changes since Ruport 0.2.2:
4
43
 
@@ -89,4 +128,4 @@ FEATURES:
89
128
 
90
129
  - new method query() will eventually replace select() / execute()
91
130
 
92
- - {examples}[http://ruport.rubyforge.org/examples.zip] available for download
131
+ - {examples}[http://ruport.rubyforge.org/] available for download
data/COPYING ADDED
@@ -0,0 +1,340 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License
307
+ along with this program; if not, write to the Free Software
308
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
+
310
+
311
+ Also add information on how to contact you by electronic and paper mail.
312
+
313
+ If the program is interactive, make it output a short notice like this
314
+ when it starts in an interactive mode:
315
+
316
+ Gnomovision version 69, Copyright (C) year name of author
317
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
+ This is free software, and you are welcome to redistribute it
319
+ under certain conditions; type `show c' for details.
320
+
321
+ The hypothetical commands `show w' and `show c' should show the appropriate
322
+ parts of the General Public License. Of course, the commands you use may
323
+ be called something other than `show w' and `show c'; they could even be
324
+ mouse-clicks or menu items--whatever suits your program.
325
+
326
+ You should also get your employer (if you work as a programmer) or your
327
+ school, if any, to sign a "copyright disclaimer" for the program, if
328
+ necessary. Here is a sample; alter the names:
329
+
330
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
+
333
+ <signature of Ty Coon>, 1 April 1989
334
+ Ty Coon, President of Vice
335
+
336
+ This General Public License does not permit incorporating your program into
337
+ proprietary programs. If your program is a subroutine library, you may
338
+ consider it more useful to permit linking proprietary applications with the
339
+ library. If this is what you want to do, use the GNU Library General
340
+ Public License instead of this License.
data/README CHANGED
@@ -6,9 +6,10 @@ of databases via DBI. It also provides helper methods and utilities to generate
6
6
 
7
7
  It happens to be alpha software, so if it offends your mother, burns out the innards of your computer, or threatens you in any other way, you may want to wait until further releases to play around with it.
8
8
 
9
- There is a set of examples and a brief walkthrough for this application
10
- available at http://ruport.rubyforge.org/example.zip which I strongly
11
- recommend going through
9
+ Please take the time to run through the examples available on RubyForge!
10
+ This is the best way of learning the system:
11
+
12
+ http://rubyforge.org/frs/?group_id=856&release_id=3656
12
13
 
13
14
  Otherwise, here is a brief set of installation and setup instructions which will
14
15
  hopefully get you going:
@@ -38,9 +39,7 @@ database combination, we'd love to hear how you did it so that we can improve
38
39
  this documentation for the next version of Ruport. Once you've got DBI
39
40
  installed, the Ruport installation is a piece of cake.
40
41
 
41
- Ruport is a gem. It relies on Parse/Input (which will be linked to Ruport
42
- in future releases) but this can easily be installed using the
43
- --include-dependencies flag. Make sure you have adequete permissions and run:
42
+ Ruport is a gem. It relies on FasterCSV but this can easily be installed using the --include-dependencies flag. Make sure you have adequete permissions and run:
44
43
 
45
44
  sudo gem install ruport
46
45
 
data/Rakefile CHANGED
@@ -14,22 +14,24 @@ end
14
14
 
15
15
  spec = Gem::Specification.new do |spec|
16
16
  spec.name = "ruport"
17
- spec.version = "0.2.5"
17
+ spec.version = "0.2.9"
18
18
  spec.platform = Gem::Platform::RUBY
19
19
  spec.summary = "A generalized Ruby report generation and templating engine."
20
20
 
21
- spec.files = Dir.glob("{bin,lib,test}/**/*.rb").
22
- delete_if { |item| item.include?("CVS") } +
23
- ["Rakefile"]
21
+ spec.files = spec.files = FileList[
22
+ 'lib/**/*.rb', 'bin/*', '[A-Z]*','test/**/*'].to_a.delete_if { |item|
23
+ item.include?("CVS") } + ["Rakefile"]
24
24
  spec.require_path = "lib"
25
25
  spec.bindir = "bin"
26
26
  spec.executables << "ruport"
27
27
 
28
+ spec.test_file = "test/ts_all.rb"
29
+
28
30
  spec.has_rdoc = true
29
31
  spec.extra_rdoc_files = %w{README LICENSE TODO AUTHORS CHANGELOG}
30
32
  spec.rdoc_options << '--title' << 'Ruport Documentation' <<
31
33
  '--main' << 'README'
32
-
34
+ spec.add_dependency('fastercsv', '>= 0.1.0')
33
35
  spec.author = "Gregory Brown"
34
36
  spec.email = " gregory.t.brown@gmail.com"
35
37
  spec.rubyforge_project = "ruport"
data/TODO CHANGED
@@ -2,10 +2,17 @@ TODO:
2
2
 
3
3
  Bugfixes:
4
4
  - Fix the manual that is in the example package so it it reads FakeDB instead
5
- of MockDB. Update the manual to cover new features in 0.2.4
5
+ of MockDB. Update the manual to cover new features in 0.3.0
6
+
7
+ - Ruport has some big trouble with running things such as table / database
8
+ creations. Gotta work out the kinks here.
6
9
 
7
10
  Improvement:
8
11
 
12
+ - Tagging... Add column and set based tagging.
13
+
14
+ - Transposition in DataSets
15
+
9
16
  - Mail system
10
17
  Make attachments doable
11
18
 
@@ -28,17 +35,16 @@ Improvement:
28
35
 
29
36
  Begin implementing new features:
30
37
 
31
- DSNs:
38
+ - Formatter:
39
+
40
+ * Implement RSS generation for Format::Builder
32
41
 
33
- It would be nice to be able to configure any number of databases
34
- and then select them by name. (JEG2)
35
-
36
- Charts:
42
+ - Charts:
37
43
 
38
44
  Build something that'll take a data set and build a chart. (SVG?),
39
45
  then dump it into PDF::Writer.
40
46
 
41
- Multiple query reports:
47
+ - Multiple query reports:
42
48
 
43
49
  Allow the user to make arbitrary SQL queries,
44
50
  combining the rows, and then iterating through them row by row in the
@@ -47,19 +53,19 @@ Begin implementing new features:
47
53
  This could be done with select taking an array of queries and possibly
48
54
  some ordering instructions
49
55
 
50
- Cross database import from file:
56
+ - Cross database import from file:
51
57
 
52
58
  Make an import(file,table,delimiter=",") command that will work
53
59
  regardless of database choice and import the data stored in a file into
54
60
  a specified table.
55
61
 
56
- Parse/Input tight integration:
62
+ - Parse/Input tight integration:
57
63
 
58
64
  Write wrapper functions over the Parse/Input library to give Ruport the
59
65
  power to feed in any data source such as a CSV, A website, or a log file
60
66
  and do formatting and use the other features of Ruport.
61
67
 
62
- PDF::Writer and CSV convenience methods:
68
+ - PDF::Writer and CSV convenience methods:
63
69
 
64
70
  Create functions that will allow basic and common reports to be built
65
71
  using PDF and CSV format without having to write the functionality over
@@ -68,13 +74,19 @@ Begin implementing new features:
68
74
 
69
75
  [UPDATE: to_csv is in place but can use some additional frosting]
70
76
 
71
- Logger / Exception handler:
77
+ - Logger / Exception handler:
72
78
 
73
79
  Create a system to handle and log errors as well as provide log messages
74
80
  regarding what Ruport does when a template is run.
75
81
 
76
82
  [UPDATE: Logger is in place but is not covering many functions]
77
83
 
84
+ - DataSets should implement tagging, allowing tag conditions to be passed and
85
+ then applied to rows. Formulas should be implemented, allowing column
86
+ generation by Proc. More about this later. (These are COOL and POWERFUL
87
+ features... thanks to Greg Gibson for the ideas.
88
+
89
+
78
90
  Design considerations:
79
91
 
80
92
  Ruport will eventually need to be cleanly seperating between formatting
data/bin/ruport CHANGED
@@ -21,19 +21,19 @@ require "ruportlib"
21
21
  # The library itself is much cleaner. This is a total hack.
22
22
 
23
23
  if ARGV[0].nil?
24
- puts "Usage: ruport path/to/template or ruport generate project_name"
24
+ puts "Usage: ruport path/to/script.rb or ruport generate project_name"
25
25
  exit
26
26
  end
27
27
 
28
28
  if ARGV[0].eql?("generate")
29
29
  if ARGV[1].nil?
30
- puts "You must specify a name for your ruport sandbox"
30
+ puts "You must specify a name for your ruport project"
31
31
  exit
32
32
  end
33
33
  Dir.mkdir(ARGV[1])
34
34
  Dir.mkdir("#{ARGV[1]}/log")
35
35
  Dir.mkdir("#{ARGV[1]}/reports")
36
- Dir.mkdir("#{ARGV[1]}/templates")
36
+ Dir.mkdir("#{ARGV[1]}/scripts")
37
37
  Dir.mkdir("#{ARGV[1]}/config")
38
38
  Dir.mkdir("#{ARGV[1]}/queries")
39
39
  conf = (<<-END_CONF
@@ -60,12 +60,12 @@ if ARGV[0].eql?("generate")
60
60
  ).gsub(" ","")
61
61
 
62
62
  File.open("#{ARGV[1]}/config/ruport.yaml", "w") { |f| f.puts(conf) }
63
- File.open("#{ARGV[1]}/templates/test.rb", "w") { |f|
64
- f.puts('query ("show tables;") do |data| @report << data.to_csv end ')
63
+ File.open("#{ARGV[1]}/scripts/test.rb", "w") { |f|
64
+ f.puts('@report = query("show tables").to_csv')
65
65
  }
66
66
  exit
67
67
  elsif ARGV[0].eql?("-v")
68
- puts "Ruport Version 0.2.5 \nA ruby report generation system by Gregory " +
68
+ puts "Ruport Version 0.2.9 \nA ruby report generation system by Gregory " +
69
69
  "Brown.\nThis application is Free Software under the GPL/Ruby License. " +
70
70
  "\nAll praise and/or criticism can be directed to "+
71
71
  "gregory.t.brown@gmail.com"
@@ -4,30 +4,61 @@ module Ruport
4
4
 
5
5
  def initialize( data_set )
6
6
  @data = data_set
7
- @type = nil
7
+ @original = data_set.dup
8
+ @format = nil
9
+ @range = nil
10
+ @header = nil
11
+ @footer = nil
12
+ @output_type = nil
8
13
  end
9
14
 
10
- attr_accessor :type
15
+ attr_accessor :format, :range, :header, :footer, :output_type
11
16
 
12
17
  def render
13
- send("render_#{@type}")
18
+ @data = @range ? ( @original[@range] ) : ( @original )
19
+ send("render_#{@format}")
14
20
  end
15
21
 
16
22
  def render_csv
17
- @data.inject(CSV.generate_line(@data.fields) + "\n") do |out,r|
18
- out << CSV.generate_line(@data.fields.map { |f| r[f] }) + "\n"
19
- end
23
+ ( @header ? "#{@header}\n\n" : "" ) +
24
+ @data.inject(FasterCSV.generate_line(@original.fields)) do |out,r|
25
+ out << FasterCSV.generate_line(@original.fields.map { |f| r[f] })
26
+ end + ( @footer ? "\n#{@footer}\n" : "" )
20
27
  end
21
-
28
+
22
29
  def render_html
23
- fields_html = "<tr>\n <td>#{@data.fields.join('</td><td>')}</td>\n </tr>"
24
- @data.inject("<table>\n #{fields_html}"){|html,row|
30
+ head_text = ( if @header
31
+ " <tr>\n <th colspan=#{@original.fields.length}>#{@header}" +
32
+ "</th>\n </tr>\n"
33
+ end )
34
+ out = "<table>\n#{head_text} <tr>\n <th>"+
35
+ "#{@original.fields.join('</th><th>')}" +
36
+ "</th>\n </tr>\n"
37
+ @data.inject(out) do |html,row|
25
38
  html << row.inject(" <tr>\n "){ |row_html, field|
26
39
  row_html << "<td>#{field}</td>"
27
- } + "\n </tr>"
28
- } + "\n</table>"
40
+ } + "\n </tr>\n"
41
+ end
42
+ foot_text = ( if @footer
43
+ " <tr>\n <th colspan=#{@original.fields.length}>#{@footer}" +
44
+ "</th>\n </tr>\n"
45
+ end )
46
+
47
+ out << "#{foot_text}</table>"
48
+ return out unless @output_type.eql?(:complete)
49
+ "<html><head><title></title></head><body>\n#{out}</body></html>\n"
29
50
  end
30
-
51
+
52
+ def render_text
53
+ header = @header ? "#{@header}\n" : ""
54
+ header << "fields: ( #{ @original.fields.join(', ') } )\n"
55
+ indices = (@range) ? @range.to_a : (0...@original.to_a.length).to_a
56
+ @data.inject(header) do |output,row|
57
+ output << "row#{indices.shift}: ( #{row.to_a.join(', ')} )\n"
58
+ end + (@footer ? "#{@footer}\n" : "" )
59
+
60
+ end
61
+
31
62
  end
32
63
  end
33
64
  end
@@ -13,7 +13,6 @@ module Ruport
13
13
 
14
14
  include Enumerable
15
15
 
16
- attr_accessor :fields
17
16
 
18
17
  # DataRows are essentially arrays with named ordinal fields and
19
18
  # awareness of their oddness and position.
@@ -22,8 +21,15 @@ module Ruport
22
21
  @fields = fields
23
22
  @oddness = oddness
24
23
  @position = position
24
+ @tags = []
25
+ end
26
+
27
+ attr_accessor :fields, :tags
28
+
29
+ #Returns an array of values.
30
+ def +(other)
31
+ self.to_a + other.to_a
25
32
  end
26
-
27
33
 
28
34
  # Lets you access individual fields
29
35
  #
@@ -41,7 +41,7 @@ module Ruport
41
41
  # are equivalent.
42
42
  def << ( stuff )
43
43
  new_row = Array.new
44
- fields.each_with_index do |key, index|
44
+ @fields.each_with_index do |key, index|
45
45
  if stuff.kind_of?(Array)
46
46
  new_row[index] = stuff.shift || @default
47
47
  else
@@ -55,8 +55,7 @@ module Ruport
55
55
  @data << DataRow.new(new_row,@fields,oddness,position)
56
56
  end
57
57
 
58
- # This works in best case scenario. It should return true if
59
- # both DataSets have the same values. Still working out the kinks here.
58
+ # checks if one dataset equals another
60
59
  def eql?(data2)
61
60
  return false unless ( @data.length == data2.data.length and
62
61
  @fields.eql?(data2.fields) )
@@ -68,14 +67,13 @@ module Ruport
68
67
 
69
68
  return true
70
69
  end
71
-
72
70
 
73
71
  # Allows loading of CSV files or YAML dumps. Returns a DataSet
74
72
  def self.load ( source, default="")
75
73
 
76
74
  return YAML.load(File.open(source)) if source =~ /\.(yaml|yml)/
77
75
 
78
- input = CSV.read(source) if source =~ /\.csv/
76
+ input = FasterCSV.read(source) if source =~ /\.csv/
79
77
  loaded_data = self.new
80
78
  loaded_data.fields = input[0]
81
79
  loaded_data.default = default
@@ -88,20 +86,68 @@ module Ruport
88
86
  # Converts a DataSet to CSV
89
87
  def to_csv
90
88
  builder = Format::Builder.new(self)
91
- builder.type = :csv
89
+ builder.format = :csv
92
90
  builder.render
93
91
  end
94
92
  # Converts a Dataset to Html
95
93
  def to_html
96
94
  builder = Format::Builder.new(self)
97
- builder.type = :html
95
+ builder.format = :html
96
+ builder.render
97
+ end
98
+
99
+ # Pretty Pretty printing
100
+ def to_s
101
+ builder = Format::Builder.new(self)
102
+ builder.format = :text
98
103
  builder.render
99
104
  end
105
+
100
106
  # Works like a standard each iterator
101
107
  def each(&action)
102
108
  @data.each(&action)
103
109
  end
104
110
 
111
+ # adds tag to rows
112
+ def apply_tag(tag,&condition)
113
+ to_tag = block_given? ? condition.call(self) : self
114
+ to_tag.each { |match| match.tags << tag }
115
+ end
116
+
117
+ def apply_tags(tags)
118
+ tags.each do |tag,block|
119
+ apply_tag(tag,&block)
120
+ end
121
+ end
122
+
123
+ def select_field(field)
124
+ my_data = Report::DataSet.new
125
+ my_data.fields = [ field ]
126
+ map { |row| row[field] }.each do |r|
127
+ my_data << [ r ]
128
+ end
129
+ return my_data
130
+ end
131
+
132
+ def select_fields(*fields)
133
+ my_data = Report::DataSet.new
134
+ my_data.fields = fields
135
+ rows = fields.inject([]) { |s,e| s << map { |row| row[e] } }.transpose
136
+ rows.each do |row|
137
+ my_data << row
138
+ end
139
+ return my_data
140
+ end
141
+
142
+ def tag_matches(tag)
143
+ my_data = Report::DataSet.new
144
+ my_data.fields = @fields
145
+ select { |row| row.tags.include?(tag) }.each do |row|
146
+ my_data << row
147
+ end
148
+ return my_data
149
+ end
150
+
105
151
  end
106
152
  end
107
153
  end
@@ -35,6 +35,11 @@ module Ruport
35
35
  @query_table = nil
36
36
  @file = nil
37
37
  @config = nil
38
+ @databases = Hash.new
39
+ @databases[:default] = { :dsn => @dsn,
40
+ :user => @user,
41
+ :password => @password
42
+ }
38
43
  end
39
44
 
40
45
  attr_accessor :query_table, :file
@@ -54,15 +59,20 @@ module Ruport
54
59
 
55
60
  def query ( statement, source = :string, &action )
56
61
  query_text = get_query(source,statement)
62
+ data = DataSet.new
57
63
  DBI.connect(@dsn, @user, @password) do |dbh|
58
- data = DataSet.new
59
- sth = dbh.execute(query_text)
60
- if block_given?
61
- data.fields = sth.column_names
62
- sth.each { |row| data << row }
63
- action.call(data)
64
+ dbh.execute(query_text) do |sth|
65
+ if sth.rows > 0
66
+ results = sth.fetch_all
67
+ data.fields = sth.column_names
68
+ results.each { |row| data << row }
69
+ action.call(data) if block_given?
70
+ else
71
+ data = nil
72
+ end
64
73
  end
65
74
  end
75
+ return data || "command succeeded. 0 rows returned"
66
76
  end
67
77
 
68
78
  # Evaluates _code_ from _filename_ as pure ruby code for files ending in
@@ -134,6 +144,12 @@ module Ruport
134
144
  raise "Could not open #{query_file}"; exit
135
145
  end
136
146
  end
147
+
148
+ def render ( data )
149
+ builder = Format::Builder.new( data )
150
+ yield(builder)
151
+ builder.render
152
+ end
137
153
 
138
154
  # Generates the report. If @pre or @post are defined with lambdas,
139
155
  # they will be called before and after the main code. generate_report
@@ -165,7 +181,20 @@ module Ruport
165
181
  @mailer.send_report(@report_name)
166
182
  end
167
183
  @post.call if @post
184
+
185
+ end
186
+
187
+ def add_dsn(label, dsn, user, password )
188
+ @databases[label] = { :dsn => dsn, :user => user,
189
+ :password => password }
190
+ end
191
+
192
+ def select_dsn(label)
193
+ @dsn = @databases[label][:dsn]
194
+ @user = @databases[label][:user]
195
+ @password = @databases[label][:password]
168
196
  end
197
+
169
198
  end
170
199
  end
171
200
  end
@@ -16,7 +16,9 @@ module Ruport
16
16
 
17
17
  def query ( query, source = :string, &action)
18
18
  query = get_query(source, query)
19
- yield(@fake_db.process(@dsn,@user,@password, query))
19
+ data = @fake_db.process(@dsn,@user,@password, query)
20
+ action.call(data) if block_given?
21
+ return data
20
22
  end
21
23
 
22
24
  end
data/lib/ruportlib.rb CHANGED
@@ -7,4 +7,5 @@ require "ruport/report/data_set"
7
7
  require "ruport/report/data_row"
8
8
  require "ruport/report/fake_mailer"
9
9
  require "ruport/format/builder"
10
+ require "faster_csv"
10
11
  include Ruport
@@ -0,0 +1,6 @@
1
+ id,name,phone,street,town,state
2
+ 1,Inky,555-000-1234,Druary Lane,Union City,CT
3
+ 2,Blinky,525-0529-123,Apple Street,Robot Town,NJ
4
+ 3,Clyde,247-219-4820,Sandbox Hill,Alvin's Landing,PA
5
+ 4,Pacman,283-102-8293,Rat Avenue,Southford,VT
6
+ 5,Mrs. Pacman,214-892-1892,Conch Walk,New York,NY
data/test/data.csv ADDED
@@ -0,0 +1,3 @@
1
+ "col1","col2","col3"
2
+ "a","b","c"
3
+ "d",,"e"
data/test/tc_builder.rb CHANGED
@@ -1,25 +1,113 @@
1
1
 
2
2
  require "test/unit"
3
- require "lib/ruportlib"
3
+ require "ruportlib"
4
4
  class TestBuilder < Test::Unit::TestCase
5
5
  def setup
6
- @data = Report::DataSet.new
7
- @data.fields = %w[ col1 col2 col3 ]
8
- @data.default = ""; @data << %w[ a b c ]; @data << %w[ d e f ]
9
- @builder = Format::Builder.new( @data )
6
+ data = Report::DataSet.new
7
+ data.fields = %w[ col1 col2 col3 ]
8
+ data.default = ""; data << %w[ a b c ]; data << %w[ d e f ]
9
+ @builder = Format::Builder.new( data )
10
10
  end
11
11
 
12
12
  def test_render_html
13
- @builder.type = :html
14
- assert_equal("<table>\n <tr>\n <td>col1</td><td>col2</td>" +
15
- "<td>col3</td>\n </tr>" +
16
- " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>" +
17
- " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>" +
18
- "\n</table>", @builder.render )
13
+ @builder.format = :html
14
+ assert_equal("<table>\n <tr>\n <th>col1</th><th>col2</th>" +
15
+ "<th>col3</th>\n </tr>\n" +
16
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
17
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
18
+ "</table>", @builder.render )
19
19
  end
20
20
 
21
+ def test_render_text
22
+ @builder.format = :text
23
+ assert_equal( "fields: ( col1, col2, col3 )\n" +
24
+ "row0: ( a, b, c )\n" +
25
+ "row1: ( d, e, f )\n", @builder.render )
26
+ end
27
+
21
28
  def test_render_csv
22
- @builder.type = :csv
29
+ @builder.format = :csv
23
30
  assert_equal("col1,col2,col3\na,b,c\nd,e,f\n", @builder.render)
24
31
  end
32
+
33
+ def test_partial_rendering
34
+ my_data = Report::DataSet.new
35
+ my_data.fields = %w[ col1 col2 col3 ]
36
+ [ %w[ a b c], %w[ d e f ], %w[ g h i ], %w[ j k l ] ].each do |row|
37
+ my_data << row
38
+ end
39
+
40
+ my_builder = Format::Builder.new( my_data )
41
+ my_builder.range = 1..2
42
+
43
+ my_builder.format = :csv
44
+ assert_equal("col1,col2,col3\nd,e,f\ng,h,i\n", my_builder.render)
45
+
46
+ my_builder.format = :html
47
+ assert_equal( "<table>\n <tr>\n <th>col1</th><th>col2</th>"+
48
+ "<th>col3</th>\n </tr>\n"+
49
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
50
+ " <tr>\n <td>g</td><td>h</td><td>i</td>\n </tr>\n" +
51
+ "</table>", my_builder.render )
52
+
53
+ my_builder.format = :text
54
+ assert_equal( "fields: ( col1, col2, col3 )\n" +
55
+ "row1: ( d, e, f )\nrow2: ( g, h, i )\n",
56
+ my_builder.render )
57
+ end
58
+
59
+ def test_complete_output
60
+ @builder.output_type = :complete
61
+ @builder.format = :html
62
+ assert_equal( "<html><head><title></title></head><body>\n"+
63
+ "<table>\n <tr>\n <th>col1</th><th>col2</th>" +
64
+ "<th>col3</th>\n </tr>\n" +
65
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
66
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
67
+ "</table></body></html>\n", @builder.render )
68
+ end
69
+
70
+ def test_header
71
+ @builder.header = "This is a sample header"
72
+ @builder.format = :csv
73
+ assert_equal( "This is a sample header\n\n" +
74
+ "col1,col2,col3\na,b,c\nd,e,f\n", @builder.render )
75
+ @builder.format = :html
76
+ assert_equal( "<table>\n <tr>\n <th colspan=3>"+
77
+ "This is a sample header</th>\n </tr>\n"+
78
+ " <tr>\n <th>col1</th><th>col2</th>" +
79
+ "<th>col3</th>\n </tr>\n" +
80
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
81
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
82
+ "</table>", @builder.render )
83
+ @builder.format = :text
84
+ assert_equal( "This is a sample header\n" +
85
+ "fields: ( col1, col2, col3 )\n" +
86
+ "row0: ( a, b, c )\n" +
87
+ "row1: ( d, e, f )\n", @builder.render )
88
+
89
+
90
+ end
91
+
92
+ def test_footer
93
+ @builder.footer = "This is a sample footer"
94
+ @builder.format = :csv
95
+ assert_equal( "col1,col2,col3\na,b,c\nd,e,f\n\n"+
96
+ "This is a sample footer\n", @builder.render )
97
+ @builder.format = :html
98
+ assert_equal( "<table>\n <tr>\n <th>col1</th><th>col2</th>" +
99
+ "<th>col3</th>\n </tr>\n" +
100
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
101
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
102
+ " <tr>\n <th colspan=3>"+
103
+ "This is a sample footer</th>\n </tr>\n"+
104
+ "</table>", @builder.render )
105
+ @builder.format = :text
106
+ assert_equal( "fields: ( col1, col2, col3 )\n" +
107
+ "row0: ( a, b, c )\n" +
108
+ "row1: ( d, e, f )\n" +
109
+ "This is a sample footer\n", @builder.render )
110
+
111
+ end
25
112
  end
113
+
data/test/tc_data_set.rb CHANGED
@@ -69,11 +69,54 @@ class TestDataSet < Test::Unit::TestCase
69
69
  end
70
70
 
71
71
  def test_to_html
72
- assert_equal("<table>\n <tr>\n <td>col1</td><td>col2</td>" +
73
- "<td>col3</td>\n </tr>" +
74
- " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>" +
75
- " <tr>\n <td>d</td><td></td><td>e</td>\n </tr>" +
76
- "\n</table>", @data.to_html )
72
+ assert_equal("<table>\n <tr>\n <th>col1</th><th>col2</th>" +
73
+ "<th>col3</th>\n </tr>\n" +
74
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
75
+ " <tr>\n <td>d</td><td></td><td>e</td>\n </tr>\n" +
76
+ "</table>", @data.to_html )
77
77
  end
78
78
 
79
+ def test_apply_tag
80
+ address_book = Report::DataSet.load("test/addressbook.csv")
81
+ address_book.apply_tag(:new_england) do |data|
82
+ data.select { |entry| %w[CT NH VT RI MA ME].include?(entry["state"]) }
83
+ end
84
+ address_book.apply_tag :generic
85
+ assert_equal( [ address_book[0], address_book[3] ],
86
+ address_book.select { |e| e.tags.include?(:new_england) } )
87
+ assert_equal( address_book.to_a,
88
+ address_book.select { |e| e.tags.include?(:generic) } )
89
+ end
90
+
91
+ def test_apply_tags
92
+ address_book = Report::DataSet.load("test/addressbook.csv")
93
+ tags = { :new_england => lambda { |data|
94
+ data.select { |e| %w[CT NH VT RI MA ME].include? e["state"] }
95
+ },
96
+ :generic => nil
97
+ }
98
+ address_book.apply_tags(tags)
99
+ assert_equal( [ address_book[0], address_book[3] ],
100
+ address_book.select { |e| e.tags.include?(:new_england) } )
101
+ assert_equal( address_book.to_a,
102
+ address_book.select { |e| e.tags.include?(:generic) } )
103
+
104
+ end
105
+
106
+ def test_select_field
107
+ assert_equal( [["a"],["d"]],
108
+ @data.select_field("col1").map { |r| r.to_a } )
109
+ assert_equal( [["b"],[""]] ,
110
+ @data.select_field("col2").map { |r| r.to_a } )
111
+ assert_equal( [["c"],["e"]],
112
+ @data.select_field("col3").map { |r| r.to_a } )
113
+ end
114
+
115
+ def test_select_fields
116
+ assert_equal( [["a","b","c"],["d","","e"]],
117
+ @data.select_fields("col1","col2","col3").map { |r| r.to_a })
118
+ assert_equal( [["c","a"],["e","d"]],
119
+ @data.select_fields("col3","col1").map { |r| r.to_a } )
120
+ end
121
+
79
122
  end
data/test/tc_engine.rb CHANGED
@@ -1,21 +1,20 @@
1
- #tc_ruport.rb
1
+ #tc_engine.rb
2
2
  #
3
3
  # Created by Gregory Thomas Brown on 2005-08-09
4
4
  # Copyright 2005 (Gregory Brown) All rights reserved.
5
5
 
6
6
  require "test/unit"
7
- require "lib/ruportlib"
7
+ require "ruportlib"
8
8
  class TestEngine < Test::Unit::TestCase
9
-
10
9
  def setup
11
- @report = Report::FakeEngine.new( "DBI:mysql:ruport:localhost",
10
+ @engine = Report::FakeEngine.new( "DBI:mysql:ruport:localhost",
12
11
  "test", "123")
13
- @report.query_table = "ruport_queries"
12
+ @engine.query_table = "ruport_queries"
14
13
 
15
- @report.fake_db = Report::FakeDB.new([ "DBI:mysql","ruport",
14
+ @engine.fake_db = Report::FakeDB.new([ "DBI:mysql","ruport",
16
15
  "localhost", "test", "123"])
17
16
 
18
- @report.fake_db["SELECT * FROM ruport_test"] = @data =
17
+ @engine.fake_db["SELECT * FROM ruport_test"] = @data =
19
18
  [ { "a" => "a column, row 1", "b" => "b column, row 1",
20
19
  "c" => "c column, row 1", "d" => "d column, row 1" },
21
20
  { "a" => "a column, row 2", "b" => "b column, row 2",
@@ -23,7 +22,7 @@ class TestEngine < Test::Unit::TestCase
23
22
  { "a" => "a column, row 3", "b" => "b column, row 3",
24
23
  "c" => "c column, row 3", "d" => "d column, row 3" } ]
25
24
 
26
- @report.fake_db[ "SELECT query FROM #{@report.query_table} " +
25
+ @engine.fake_db[ "SELECT query FROM #{@engine.query_table} " +
27
26
  "WHERE label LIKE 'sql_stored_test';"] =
28
27
  [ "query" => "SELECT * FROM ruport_test" ]
29
28
  end
@@ -32,19 +31,19 @@ class TestEngine < Test::Unit::TestCase
32
31
  contents = "SELECT * FROM ruport_test"
33
32
 
34
33
  #relative to working dir
35
- assert_equal(contents, @report.load_file("test/test.sql"));
34
+ assert_equal(contents, @engine.load_file("test/test.sql"));
36
35
 
37
36
  #absolute path
38
37
  assert_equal(contents,
39
- @report.load_file(File.expand_path("test/test.sql")))
38
+ @engine.load_file(File.expand_path("test/test.sql")))
40
39
  end
41
40
 
42
41
  def test_sql_generation
43
- sql = @report.fetch do
42
+ sql = @engine.fetch do
44
43
  from :ruport_test
45
44
  end
46
45
  assert_equal("SELECT * FROM ruport_test;", sql)
47
- sql = @report.fetch do
46
+ sql = @engine.fetch do
48
47
  from :ruport_test
49
48
  condition :last_name, :"=", "Brown"
50
49
  order :first_name
@@ -57,28 +56,47 @@ class TestEngine < Test::Unit::TestCase
57
56
  config_hash = { :name => "Greg",
58
57
  :friend => "Rob",
59
58
  :job => "Programmer" }
60
- @report.load_yaml "test/test.yaml"
59
+ @engine.load_yaml "test/test.yaml"
61
60
  config_hash.each do |key, value|
62
- assert_equal(value,@report.config[key])
61
+ assert_equal(value,@engine.config[key])
63
62
  end
64
63
  end
65
64
 
66
65
  def test_sql_file
67
- @report.query("test/test.sql",:file) do |result|
66
+ @engine.query("test/test.sql",:file) do |result|
68
67
  assert_equal(@data,result)
69
68
  end
70
69
  end
71
70
 
72
71
  def test_sql_stored
73
- @report.query("sql_stored_test",:db) do |result|
72
+ @engine.query("sql_stored_test",:db) do |result|
74
73
  assert_equal(@data,result)
75
74
  end
76
75
  end
77
76
 
78
77
  def test_query
79
- @report.query("SELECT * FROM ruport_test") do |result|
78
+ @engine.query("SELECT * FROM ruport_test") do |result|
80
79
  assert_equal(@data,result)
81
80
  end
82
81
  end
82
+
83
+ def test_render
84
+ data = Report::DataSet.new
85
+ data.fields = %w[ col1 col2 col3]
86
+ data << %w[ a b c]
87
+ data << %w[ d e f]
88
+ assert_equal("col1,col2,col3\na,b,c\nd,e,f\n",
89
+ @engine.render(data) do |builder|
90
+ builder.format = :csv
91
+ end )
92
+
93
+ assert_equal("<table>\n <tr>\n <th>col1</th><th>col2</th>" +
94
+ "<th>col3</th>\n </tr>\n" +
95
+ " <tr>\n <td>a</td><td>b</td><td>c</td>\n </tr>\n" +
96
+ " <tr>\n <td>d</td><td>e</td><td>f</td>\n </tr>\n" +
97
+ "</table>", @engine.render(data) do |builder|
98
+ builder.format = :html
99
+ end )
100
+ end
83
101
 
84
102
  end
data/test/test.sql ADDED
@@ -0,0 +1 @@
1
+ SELECT * FROM ruport_test
data/test/test.yaml ADDED
@@ -0,0 +1,3 @@
1
+ :name: Greg
2
+ :friend: Rob
3
+ :job: Programmer
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.5
7
- date: 2005-11-16 00:00:00 -06:00
6
+ version: 0.2.9
7
+ date: 2005-11-28
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
10
  - lib
@@ -24,8 +24,6 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
24
  version: 0.0.0
25
25
  version:
26
26
  platform: ruby
27
- signing_key:
28
- cert_chain:
29
27
  authors:
30
28
  - Gregory Brown
31
29
  files:
@@ -40,19 +38,26 @@ files:
40
38
  - lib/ruport/report/fake_mailer.rb
41
39
  - lib/ruport/report/mailer.rb
42
40
  - lib/ruport/report/sql.rb
41
+ - bin/ruport
42
+ - AUTHORS
43
+ - CHANGELOG
44
+ - COPYING
45
+ - LICENSE
46
+ - Rakefile
47
+ - README
48
+ - TODO
49
+ - test/addressbook.csv
50
+ - test/data.csv
43
51
  - test/tc_builder.rb
44
52
  - test/tc_data_row.rb
45
53
  - test/tc_data_set.rb
46
54
  - test/tc_engine.rb
47
55
  - test/tc_mailer.rb
56
+ - test/test.sql
57
+ - test/test.yaml
58
+ - test/ts_all.rb
59
+ test_files:
48
60
  - test/ts_all.rb
49
- - Rakefile
50
- - README
51
- - LICENSE
52
- - TODO
53
- - AUTHORS
54
- - CHANGELOG
55
- test_files: []
56
61
  rdoc_options:
57
62
  - "--title"
58
63
  - Ruport Documentation
@@ -68,4 +73,14 @@ executables:
68
73
  - ruport
69
74
  extensions: []
70
75
  requirements: []
71
- dependencies: []
76
+ dependencies:
77
+ - !ruby/object:Gem::Dependency
78
+ name: fastercsv
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Version::Requirement
81
+ requirements:
82
+ -
83
+ - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.1.0
86
+ version: