ruport 0.2.9 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/ACKNOWLEDGEMENTS +33 -0
  2. data/AUTHORS +13 -1
  3. data/CHANGELOG +76 -1
  4. data/README +208 -89
  5. data/Rakefile +12 -8
  6. data/TODO +14 -122
  7. data/lib/ruport.rb +58 -0
  8. data/lib/ruport/config.rb +114 -0
  9. data/lib/ruport/data_row.rb +144 -0
  10. data/lib/ruport/data_set.rb +221 -0
  11. data/lib/ruport/format.rb +116 -0
  12. data/lib/ruport/format/builder.rb +29 -5
  13. data/lib/ruport/format/document.rb +77 -0
  14. data/lib/ruport/format/open_node.rb +36 -0
  15. data/lib/ruport/parser.rb +202 -0
  16. data/lib/ruport/query.rb +208 -0
  17. data/lib/ruport/query/sql_split.rb +33 -0
  18. data/lib/ruport/report.rb +116 -0
  19. data/lib/ruport/report/mailer.rb +17 -15
  20. data/test/{addressbook.csv → samples/addressbook.csv} +0 -0
  21. data/test/samples/car_ads.txt +505 -0
  22. data/test/{data.csv → samples/data.csv} +0 -0
  23. data/test/samples/document.xml +22 -0
  24. data/test/samples/five_lines.txt +5 -0
  25. data/test/samples/five_paragraphs.txt +9 -0
  26. data/test/samples/ross_report.txt +58530 -0
  27. data/test/samples/ruport_test.sql +8 -0
  28. data/test/samples/stonecodeblog.sql +279 -0
  29. data/test/{test.sql → samples/test.sql} +2 -1
  30. data/test/{test.yaml → samples/test.yaml} +0 -0
  31. data/test/tc_builder.rb +7 -4
  32. data/test/tc_config.rb +41 -0
  33. data/test/tc_data_row.rb +16 -26
  34. data/test/tc_data_set.rb +60 -41
  35. data/test/tc_database.rb +25 -0
  36. data/test/tc_document.rb +42 -0
  37. data/test/tc_element.rb +18 -0
  38. data/test/tc_page.rb +42 -0
  39. data/test/tc_query.rb +55 -0
  40. data/test/tc_reading.rb +60 -0
  41. data/test/tc_report.rb +31 -0
  42. data/test/tc_section.rb +45 -0
  43. data/test/tc_sql_split.rb +18 -0
  44. data/test/tc_state.rb +142 -0
  45. data/test/ts_all.rb +6 -3
  46. data/test/ts_format.rb +5 -0
  47. data/test/ts_parser.rb +10 -0
  48. metadata +102 -60
  49. data/bin/ruport +0 -104
  50. data/lib/ruport/format/chart.rb +0 -1
  51. data/lib/ruport/report/data_row.rb +0 -79
  52. data/lib/ruport/report/data_set.rb +0 -153
  53. data/lib/ruport/report/engine.rb +0 -201
  54. data/lib/ruport/report/fake_db.rb +0 -54
  55. data/lib/ruport/report/fake_engine.rb +0 -26
  56. data/lib/ruport/report/fake_mailer.rb +0 -23
  57. data/lib/ruport/report/sql.rb +0 -95
  58. data/lib/ruportlib.rb +0 -11
  59. data/test/tc_engine.rb +0 -102
  60. data/test/tc_mailer.rb +0 -21
data/test/ts_all.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "test/unit"
2
- require "test/tc_engine"
2
+ require "test/ts_format"
3
+ require "test/ts_parser"
4
+ require "test/tc_sql_split"
5
+ require "test/tc_query"
6
+ require "test/tc_config"
7
+ require "test/tc_report"
3
8
  require "test/tc_data_set"
4
9
  require "test/tc_data_row"
5
- require "test/tc_builder"
6
- require "test/tc_mailer"
data/test/ts_format.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "test/tc_builder"
2
+ require "test/tc_document"
3
+ require "test/tc_element"
4
+ require "test/tc_section"
5
+ require "test/tc_page"
data/test/ts_parser.rb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # ts_all.rb
4
+ #
5
+ # Created by James Edward Gray II on 2005-08-14.
6
+ # Copyright 2005 Gray Productions. All rights reserved.
7
+
8
+ require "test/unit"
9
+ require "tc_reading"
10
+ require "tc_state"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.9
7
- date: 2005-11-28
6
+ version: 0.3.8
7
+ date: 2006-02-21 00:00:00 -05:00
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: "\tgregory.t.brown@gmail.com"
12
12
  homepage: http://ruport.rubyforge.org
13
13
  rubyforge_project: ruport
@@ -18,69 +18,111 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
27
28
  authors:
28
- - Gregory Brown
29
+ - Gregory Brown
29
30
  files:
30
- - lib/ruportlib.rb
31
- - lib/ruport/format/builder.rb
32
- - lib/ruport/format/chart.rb
33
- - lib/ruport/report/data_row.rb
34
- - lib/ruport/report/data_set.rb
35
- - lib/ruport/report/engine.rb
36
- - lib/ruport/report/fake_db.rb
37
- - lib/ruport/report/fake_engine.rb
38
- - lib/ruport/report/fake_mailer.rb
39
- - lib/ruport/report/mailer.rb
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
51
- - test/tc_builder.rb
52
- - test/tc_data_row.rb
53
- - test/tc_data_set.rb
54
- - test/tc_engine.rb
55
- - test/tc_mailer.rb
56
- - test/test.sql
57
- - test/test.yaml
58
- - test/ts_all.rb
31
+ - lib/ruport.rb
32
+ - lib/ruport/data_set.rb
33
+ - lib/ruport/config.rb
34
+ - lib/ruport/format.rb
35
+ - lib/ruport/report.rb
36
+ - lib/ruport/query.rb
37
+ - lib/ruport/data_row.rb
38
+ - lib/ruport/parser.rb
39
+ - lib/ruport/format/document.rb
40
+ - lib/ruport/format/builder.rb
41
+ - lib/ruport/format/open_node.rb
42
+ - lib/ruport/report/mailer.rb
43
+ - lib/ruport/query/sql_split.rb
44
+ - CHANGELOG
45
+ - LICENSE
46
+ - Rakefile
47
+ - AUTHORS
48
+ - TODO
49
+ - COPYING
50
+ - README
51
+ - ACKNOWLEDGEMENTS
52
+ - test/samples
53
+ - test/tc_element.rb
54
+ - test/ts_all.rb
55
+ - test/tc_data_row.rb
56
+ - test/tc_state.rb
57
+ - test/tc_section.rb
58
+ - test/tc_database.rb
59
+ - test/tc_config.rb
60
+ - test/ts_format.rb
61
+ - test/ts_parser.rb
62
+ - test/tc_sql_split.rb
63
+ - test/tc_report.rb
64
+ - test/tc_page.rb
65
+ - test/tc_document.rb
66
+ - test/tc_data_set.rb
67
+ - test/tc_builder.rb
68
+ - test/tc_query.rb
69
+ - test/tc_reading.rb
70
+ - test/samples/stonecodeblog.sql
71
+ - test/samples/ruport_test.sql
72
+ - test/samples/test.yaml
73
+ - test/samples/data.csv
74
+ - test/samples/car_ads.txt
75
+ - test/samples/addressbook.csv
76
+ - test/samples/document.xml
77
+ - test/samples/test.sql
78
+ - test/samples/five_lines.txt
79
+ - test/samples/five_paragraphs.txt
80
+ - test/samples/ross_report.txt
59
81
  test_files:
60
- - test/ts_all.rb
82
+ - test/ts_all.rb
61
83
  rdoc_options:
62
- - "--title"
63
- - Ruport Documentation
64
- - "--main"
65
- - README
84
+ - --title
85
+ - Ruport Documentation
86
+ - --main
87
+ - README
88
+ - -q
66
89
  extra_rdoc_files:
67
- - README
68
- - LICENSE
69
- - TODO
70
- - AUTHORS
71
- - CHANGELOG
72
- executables:
73
- - ruport
90
+ - README
91
+ - LICENSE
92
+ - TODO
93
+ - AUTHORS
94
+ - CHANGELOG
95
+ executables: []
96
+
74
97
  extensions: []
98
+
75
99
  requirements: []
100
+
76
101
  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:
102
+ - !ruby/object:Gem::Dependency
103
+ name: fastercsv
104
+ version_requirement:
105
+ version_requirements: !ruby/object:Gem::Version::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.1.0
110
+ version:
111
+ - !ruby/object:Gem::Dependency
112
+ name: RedCloth
113
+ version_requirement:
114
+ version_requirements: !ruby/object:Gem::Version::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 3.0.0
119
+ version:
120
+ - !ruby/object:Gem::Dependency
121
+ name: pdf-writer
122
+ version_requirement:
123
+ version_requirements: !ruby/object:Gem::Version::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 1.1.3
128
+ version:
data/bin/ruport DELETED
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # ruport.rb : A Ruby Reporting system.
3
- #
4
- # Created by Gregory Thomas Brown on 2005-08-02
5
- # Copyright (c) 2005 Gregory Brown, Stone Code Productions
6
- # All rights reserved.
7
- #
8
- # This product is free software, you may distribute it as such
9
- # under your choice of the Ruby license or the GNU GPL
10
- # See LICENSE for details
11
- #
12
- # Special thanks and acknowledgement go to James Edward Gray II
13
- # for providing the original source code for this application
14
-
15
- require "rubygems"
16
- require "ftools"
17
- require "yaml"
18
- require "ruportlib"
19
-
20
- # The whole codebase below is scary, dirty, and evil.
21
- # The library itself is much cleaner. This is a total hack.
22
-
23
- if ARGV[0].nil?
24
- puts "Usage: ruport path/to/script.rb or ruport generate project_name"
25
- exit
26
- end
27
-
28
- if ARGV[0].eql?("generate")
29
- if ARGV[1].nil?
30
- puts "You must specify a name for your ruport project"
31
- exit
32
- end
33
- Dir.mkdir(ARGV[1])
34
- Dir.mkdir("#{ARGV[1]}/log")
35
- Dir.mkdir("#{ARGV[1]}/reports")
36
- Dir.mkdir("#{ARGV[1]}/scripts")
37
- Dir.mkdir("#{ARGV[1]}/config")
38
- Dir.mkdir("#{ARGV[1]}/queries")
39
- conf = (<<-END_CONF
40
- # any DBI driver ('DBI:mysql', 'DBI:odbc', etc) or Ruport's mock ('ruport')
41
- :driver:
42
-
43
- #The database to connect to. For remote database: 'foo:hostname' or 'foo:ip'
44
- :database:
45
-
46
- # username. for local auth, leave blank
47
- :db_user:
48
-
49
- :db_password:
50
-
51
- #mail info, if you want mail support, fill out. Otherwise leave blank
52
- :mail_host:
53
- :mail_account:
54
- :mail_password:
55
- :mail_address:
56
- :mail_authentication:
57
- :query_table:
58
-
59
- END_CONF
60
- ).gsub(" ","")
61
-
62
- File.open("#{ARGV[1]}/config/ruport.yaml", "w") { |f| f.puts(conf) }
63
- File.open("#{ARGV[1]}/scripts/test.rb", "w") { |f|
64
- f.puts('@report = query("show tables").to_csv')
65
- }
66
- exit
67
- elsif ARGV[0].eql?("-v")
68
- puts "Ruport Version 0.2.9 \nA ruby report generation system by Gregory " +
69
- "Brown.\nThis application is Free Software under the GPL/Ruby License. " +
70
- "\nAll praise and/or criticism can be directed to "+
71
- "gregory.t.brown@gmail.com"
72
- exit
73
- end
74
- unless (File.exist?("config/ruport.yaml"))
75
- puts "You are trying to execute ruport from outside a ruport folder"
76
- exit
77
- end
78
- config = YAML.load(File.open("config/ruport.yaml"))
79
- mailer = nil
80
-
81
- if config.has_key?(:mail_host)
82
- mailer = Report::Mailer.new( config[:mail_host], config[:mail_address],
83
- config[:mail_account], config[:mail_password],
84
- 25, config[:mail_authentication] )
85
- end
86
-
87
- report = Report::Engine.new(
88
- "#{config[:driver]}:#{config[:database]}",
89
- config[:db_user], config[:db_password], mailer )
90
-
91
- if config[:driver].eql?("ruport")
92
- report = Report::FakeEngine.new( "#{config[:driver]}:#{config[:database]}",
93
- config[:db_user], config[:db_password], mailer )
94
- end
95
-
96
- report.query_table = config[:query_table]
97
- report.file = ARGV[1] unless ARGV[1].nil?
98
- unless ( File.exists? ARGV[0] )
99
- report.logger.fatal("Could not open #{ARGV[0]}")
100
- puts "Could not open #{ARGV[0]}"
101
- exit
102
- end
103
- report.eval_report(ARGV[0], File.open(ARGV[0]) { |f| f.read })
104
- report.generate_report if report.generate
@@ -1 +0,0 @@
1
- # Do me!
@@ -1,79 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- # data_row.rb
3
- # Created by Gregory Thomas Brown on 2005-08-02
4
- # Copyright 2005 (Gregory Brown) All rights reserved.
5
- #
6
- # This product is free software, you may distribute it as such
7
- # under your choice of the Ruby license or the GNU GPL
8
- # See LICENSE for details
9
-
10
- module Ruport
11
- module Report
12
- class DataRow
13
-
14
- include Enumerable
15
-
16
-
17
- # DataRows are essentially arrays with named ordinal fields and
18
- # awareness of their oddness and position.
19
- def initialize( data, fields, oddness=nil, position=nil )
20
- @data = data
21
- @fields = fields
22
- @oddness = oddness
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
32
- end
33
-
34
- # Lets you access individual fields
35
- #
36
- # i.e. row["phone"]
37
- def [](key)
38
- key.kind_of?(Fixnum) ? @data[key] : @data[@fields.index(key)]
39
- end
40
-
41
- # Lets you set field values
42
- #
43
- # i.e. row["phone"] = '2038291203'
44
- def []=(key,value)
45
- key.kind_of?(String) ? @data[@fields.index(key)] = value :
46
- @data[key] = value
47
- end
48
-
49
- # Converts the DataRow to a plain old Array
50
- def to_a
51
- @data
52
- end
53
-
54
- # Converts the DataRow to a string representation
55
- # for outputting to screen.
56
- def to_s
57
- "[" + @data.join(",") + "]"
58
- end
59
-
60
- # implements
61
- # DataRow#first? DataRow#last? DataRow#middle?
62
- # DataRow#odd? DataRow#even? which are all conditional methods.
63
- def method_missing(method)
64
- if %[last? first? center?].include? method.to_s
65
- return @position.eql?(method.to_s[0..-2].to_sym)
66
- elsif %[odd? even?].include? method.to_s
67
- return @oddness.eql?(method.to_s[0..-2].to_sym)
68
- end
69
- super
70
- end
71
-
72
- def each(&action)
73
- @data.each(&action)
74
- end
75
-
76
- attr_accessor :position
77
- end
78
- end
79
- end
@@ -1,153 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- # data_set.rb
3
- # Created by Gregory Thomas Brown on 2005-08-02
4
- # Copyright 2005 (Gregory Brown) All rights reserved.
5
- #
6
- # This product is free software, you may distribute it as such
7
- # under your choice of the Ruby license or the GNU GPL
8
- # See LICENSE for details
9
- module Ruport
10
- module Report
11
- class DataSet
12
-
13
- include Enumerable
14
-
15
- def initialize
16
- @data = []
17
- end
18
-
19
- #fields are the column names, default is the default cell value
20
- attr_accessor :fields, :default
21
-
22
- #data is the core Array that holds all the rows
23
- attr_reader :data
24
-
25
-
26
- #Allows ordinal access to rows
27
- def [](index)
28
- @data[index]
29
- end
30
-
31
- #allows setting of rows (providing a DataRow is passed in)
32
- def []=(index,value)
33
- throw "Invalid object type" unless value.kind_of?(DataRow)
34
- @data[index] = value
35
- end
36
-
37
- # appends a row to the DataSet
38
- # can be added as an array or a keyed hash.
39
- # i.e if our DataSet have @fields = [:a, :b, :c]
40
- # data << [ 1, 2, 3] and data << { :a => 1, :b => 2, :c => 3 }
41
- # are equivalent.
42
- def << ( stuff )
43
- new_row = Array.new
44
- @fields.each_with_index do |key, index|
45
- if stuff.kind_of?(Array)
46
- new_row[index] = stuff.shift || @default
47
- else
48
- new_row[index] = stuff[key] || @default
49
- end
50
- end
51
-
52
- oddness = (@data.length % 2 == 0 ? :even : :odd)
53
- position = (@data.length == 0 ? :first : :last)
54
- @data[@data.length - 1].position = nil if @data.length > 1
55
- @data << DataRow.new(new_row,@fields,oddness,position)
56
- end
57
-
58
- # checks if one dataset equals another
59
- def eql?(data2)
60
- return false unless ( @data.length == data2.data.length and
61
- @fields.eql?(data2.fields) )
62
- @data.each_with_index do |row, r_index|
63
- row.each_with_index do |field, f_index|
64
- return false unless field.eql?(data2[r_index][f_index])
65
- end
66
- end
67
-
68
- return true
69
- end
70
-
71
- # Allows loading of CSV files or YAML dumps. Returns a DataSet
72
- def self.load ( source, default="")
73
-
74
- return YAML.load(File.open(source)) if source =~ /\.(yaml|yml)/
75
-
76
- input = FasterCSV.read(source) if source =~ /\.csv/
77
- loaded_data = self.new
78
- loaded_data.fields = input[0]
79
- loaded_data.default = default
80
- input[1..-1].each do |row|
81
- loaded_data << row
82
- end
83
- return loaded_data
84
- end
85
-
86
- # Converts a DataSet to CSV
87
- def to_csv
88
- builder = Format::Builder.new(self)
89
- builder.format = :csv
90
- builder.render
91
- end
92
- # Converts a Dataset to Html
93
- def to_html
94
- builder = Format::Builder.new(self)
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
103
- builder.render
104
- end
105
-
106
- # Works like a standard each iterator
107
- def each(&action)
108
- @data.each(&action)
109
- end
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
-
151
- end
152
- end
153
- end