ruport 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +7 -3
- data/Rakefile +8 -9
- data/TODO +16 -0
- data/examples/RWEmerson.jpg +0 -0
- data/examples/centered_pdf_text_box.rb +66 -0
- data/examples/invoice.rb +35 -25
- data/examples/invoice_report.rb +1 -1
- data/examples/line_plotter.rb +1 -1
- data/examples/pdf_table_with_title.rb +42 -0
- data/lib/ruport.rb +5 -7
- data/lib/ruport.rb.rej +41 -0
- data/lib/ruport.rb~ +85 -0
- data/lib/ruport/attempt.rb +59 -59
- data/lib/ruport/config.rb +15 -4
- data/lib/ruport/data.rb +0 -2
- data/lib/ruport/data/groupable.rb +25 -16
- data/lib/ruport/data/record.rb +128 -102
- data/lib/ruport/data/table.rb +352 -199
- data/lib/ruport/data/taggable.rb +18 -7
- data/lib/ruport/format/html.rb +3 -1
- data/lib/ruport/format/latex.rb +1 -1
- data/lib/ruport/format/latex.rb.rej +26 -0
- data/lib/ruport/format/latex.rb~ +47 -0
- data/lib/ruport/format/pdf.rb +111 -28
- data/lib/ruport/format/pdf.rb.rej +168 -0
- data/lib/ruport/format/pdf.rb~ +189 -0
- data/lib/ruport/format/plugin.rb +0 -5
- data/lib/ruport/format/svg.rb +4 -4
- data/lib/ruport/format/xml.rb +3 -3
- data/lib/ruport/generator.rb +66 -27
- data/lib/ruport/mailer.rb +4 -1
- data/lib/ruport/query.rb +13 -1
- data/lib/ruport/renderer.rb +89 -17
- data/lib/ruport/renderer/graph.rb +5 -5
- data/lib/ruport/renderer/table.rb +8 -9
- data/lib/ruport/report.rb +2 -6
- data/test/test_config.rb +88 -76
- data/test/{test_text_table.rb → test_format_text.rb} +4 -2
- data/test/test_groupable.rb +15 -13
- data/test/test_query.rb +6 -3
- data/test/test_record.rb +57 -33
- data/test/test_renderer.rb +77 -0
- data/test/test_report.rb +188 -181
- data/test/test_ruport.rb +5 -6
- data/test/test_table.rb +290 -190
- data/test/test_table_renderer.rb +56 -8
- data/test/test_taggable.rb +7 -8
- data/test/unit.log +259 -7
- metadata +22 -19
- data/lib/ruport/data/collection.rb +0 -65
- data/lib/ruport/data/set.rb +0 -148
- data/test/test_collection.rb +0 -30
- data/test/test_set.rb +0 -118
@@ -1,65 +0,0 @@
|
|
1
|
-
# The Ruport Data Collections.
|
2
|
-
# Authors: Gregory Brown / Dudley Flanders
|
3
|
-
#
|
4
|
-
# This is Free Software. For details, see LICENSE and COPYING
|
5
|
-
# Copyright 2006 by respective content owners, all rights reserved.
|
6
|
-
|
7
|
-
module Ruport::Data
|
8
|
-
|
9
|
-
# === Overview
|
10
|
-
#
|
11
|
-
# This is the base class for Ruport's Data structures. It mixes in the
|
12
|
-
# <tt>Taggable</tt> module and provides methods for converting between
|
13
|
-
# <tt>Data::Set</tt>s and <tt>Data::Table</tt>s.
|
14
|
-
#
|
15
|
-
class Collection
|
16
|
-
require "forwardable"
|
17
|
-
extend Forwardable
|
18
|
-
include Enumerable
|
19
|
-
include Taggable
|
20
|
-
|
21
|
-
def initialize(data=nil,options={}) #:nodoc:
|
22
|
-
@data = data.dup if data
|
23
|
-
end
|
24
|
-
|
25
|
-
# A simple formatting tool which allows you to quickly generate a formatted
|
26
|
-
# table from a <tt>Collection</tt> object.
|
27
|
-
#
|
28
|
-
# If given a block, the Renderer::Table object will be yielded
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# Examples:
|
32
|
-
#
|
33
|
-
# my_collection.as(:csv) #=> "1,2,3\n4,5,6"
|
34
|
-
#
|
35
|
-
# my_collection.as(:csv) { |e| e.layout.show_table_headers = false }
|
36
|
-
def as(type)
|
37
|
-
Ruport::Renderer::Table.render(type) do |rend|
|
38
|
-
rend.data = self
|
39
|
-
yield(rend) if block_given?
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Converts a <tt>Collection</tt> object to a <tt>Data::Set</tt>.
|
44
|
-
def to_set
|
45
|
-
Set.new :data => data
|
46
|
-
end
|
47
|
-
|
48
|
-
# Converts a <tt>Collection</tt> object to a <tt>Data::Table</tt>.
|
49
|
-
def to_table(options={})
|
50
|
-
Table.new({:data => data.map { |r| r.to_a }}.merge(options))
|
51
|
-
end
|
52
|
-
|
53
|
-
# Provides a shortcut for the <tt>as()</tt> method by converting a call to
|
54
|
-
# <tt>as(:format_name)</tt> into a call to <tt>to_format_name</tt>
|
55
|
-
#
|
56
|
-
def method_missing(id,*args)
|
57
|
-
return as($1.to_sym) if id.to_s =~ /^to_(.*)/
|
58
|
-
super
|
59
|
-
end
|
60
|
-
|
61
|
-
attr_reader :data
|
62
|
-
def_delegators :@data, :each, :length, :size, :empty?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
data/lib/ruport/data/set.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# The Ruport Data Collections.
|
2
|
-
# Authors: Gregory Brown / Dudley Flanders
|
3
|
-
#
|
4
|
-
# This is Free Software. For details, see LICENSE and COPYING
|
5
|
-
# Copyright 2006 by respective content owners, all rights reserved.
|
6
|
-
require 'set'
|
7
|
-
|
8
|
-
module Ruport::Data
|
9
|
-
|
10
|
-
# === Overview
|
11
|
-
#
|
12
|
-
# This class is one of the core classes for building and working with data
|
13
|
-
# in Ruport. The idea is to get your data into a standard form, regardless
|
14
|
-
# of its source (a database, manual arrays, ActiveRecord, CSVs, etc.).
|
15
|
-
#
|
16
|
-
# Set is intended to be used as the data store for unstructured data -
|
17
|
-
# Ruport::Data::Table is an alternate data store intended for structured,
|
18
|
-
# tabular data.
|
19
|
-
#
|
20
|
-
# Once your data is in a Ruport::Data::Set object, it can be manipulated
|
21
|
-
# to suit your needs, then used to build a report.
|
22
|
-
#
|
23
|
-
class Set < Collection
|
24
|
-
|
25
|
-
# Creates a new Set containing the elements of <tt>options[:data]</tt>.
|
26
|
-
#
|
27
|
-
# Example:
|
28
|
-
#
|
29
|
-
# Set.new :data => [%w[one two three] %w[1 2 3] %w[I II III]]
|
30
|
-
#
|
31
|
-
def initialize(options={})
|
32
|
-
@data = ::Set.new
|
33
|
-
options[:data].each {|e| self << e} if options[:data]
|
34
|
-
end
|
35
|
-
|
36
|
-
# Adds the given object to the Set and returns self.
|
37
|
-
#
|
38
|
-
# Example:
|
39
|
-
#
|
40
|
-
# set = Set.new :data => [%w[one two three]]
|
41
|
-
# set << [5,6,7]
|
42
|
-
#
|
43
|
-
def add(other)
|
44
|
-
case other
|
45
|
-
when Record
|
46
|
-
@data << other
|
47
|
-
when Array
|
48
|
-
@data << Record.new(other)
|
49
|
-
end
|
50
|
-
self
|
51
|
-
end
|
52
|
-
alias_method :<<, :add
|
53
|
-
|
54
|
-
# Produces a shallow copy of the Set: the same data elements are
|
55
|
-
# referenced by both the old and new Sets.
|
56
|
-
#
|
57
|
-
# Example:
|
58
|
-
#
|
59
|
-
# set = Set.new :data => [%w[one two three]]
|
60
|
-
# set2 = set.dup
|
61
|
-
# set == set2 #=> true
|
62
|
-
# set << [8,9,10]
|
63
|
-
# set == set2 #=> false
|
64
|
-
#
|
65
|
-
def dup
|
66
|
-
a = self.class.new(:data=>@data)
|
67
|
-
a.tags = tags.dup
|
68
|
-
return a
|
69
|
-
end
|
70
|
-
alias_method :clone, :dup
|
71
|
-
|
72
|
-
# Two Sets are equal if they contain the same set of objects.
|
73
|
-
#
|
74
|
-
# Example:
|
75
|
-
# s1 = Set.new :data => [[1,2,3]]
|
76
|
-
# s2 = Set.new :data => [[1,2,3]]
|
77
|
-
# s1 == s2 #=> true
|
78
|
-
#
|
79
|
-
def ==(other)
|
80
|
-
@data == other.data
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns a new Set containing the all of the objects contained in either
|
84
|
-
# of the two Sets.
|
85
|
-
#
|
86
|
-
# Example:
|
87
|
-
#
|
88
|
-
# s1 = Set.new :data => [[1,2,3]]
|
89
|
-
# s2 = Set.new :data => [[4,5,6]]
|
90
|
-
# s3 = s1 | s2
|
91
|
-
# s4 = Set.new :data => [[1,2,3], [4,5,6]]
|
92
|
-
# s3 == s4 #=> true
|
93
|
-
#
|
94
|
-
def |(other)
|
95
|
-
Set.new :data => (@data | other.data)
|
96
|
-
end
|
97
|
-
alias_method :union, :|
|
98
|
-
alias_method :+, :|
|
99
|
-
|
100
|
-
# Returns a new Set containing the objects common to the two Sets.
|
101
|
-
#
|
102
|
-
# Example:
|
103
|
-
#
|
104
|
-
# s1 = Set.new :data => [%w[a b c],[1,2,3]]
|
105
|
-
# s2 = Set.new :data => [%w[a b c],[4,5,6]]
|
106
|
-
# s3 = s1 & s2
|
107
|
-
# s4 = Set.new :data => [%w[a b c]]
|
108
|
-
# s3 == s4 #=> true
|
109
|
-
#
|
110
|
-
def &(other)
|
111
|
-
Set.new :data => (@data & other.data)
|
112
|
-
end
|
113
|
-
alias_method :intersection, :&
|
114
|
-
|
115
|
-
# Returns a new Set containing those objects present in this Set but not
|
116
|
-
# the other.
|
117
|
-
#
|
118
|
-
# Example:
|
119
|
-
#
|
120
|
-
# s1 = Set.new :data => [%w[a b c],[1,2,3]]
|
121
|
-
# s2 = Set.new :data => [%w[a b c],[4,5,6]]
|
122
|
-
# s3 = s1 - s2
|
123
|
-
# s4 = Set.new :data => [[1, 2, 3]]
|
124
|
-
# s3 == s4 #=> true
|
125
|
-
#
|
126
|
-
def -(other)
|
127
|
-
Set.new :data => (@data - other.data)
|
128
|
-
end
|
129
|
-
alias_method :difference, :-
|
130
|
-
|
131
|
-
# Returns a new Set containing those objects that are either in this Set
|
132
|
-
# or the other Set but not in both.
|
133
|
-
#
|
134
|
-
# Example:
|
135
|
-
#
|
136
|
-
# s1 = Set.new :data => [%w[a b c],[1,2,3]]
|
137
|
-
# s2 = Set.new :data => [%w[a b c],[4,5,6]]
|
138
|
-
# s3 = s1 ^ s2
|
139
|
-
# s4 = Set.new :data => [[1, 2, 3],[4,5,6]]
|
140
|
-
# s3 == s4 #=> true
|
141
|
-
#
|
142
|
-
def ^(other)
|
143
|
-
Set.new :data => (@data ^ other.data)
|
144
|
-
end
|
145
|
-
|
146
|
-
def_delegators :@data, :each
|
147
|
-
end
|
148
|
-
end
|
data/test/test_collection.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "ruport"
|
3
|
-
begin; require "rubygems"; rescue LoadError; nil; end
|
4
|
-
class TestCollection < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@ghosts = Ruport::Data::Collection.new %w[inky blinky clyde]
|
8
|
-
@ghost_list = [["inky", "blue"],["blinky","red"],["clyde","orange"]]
|
9
|
-
@ghost_records = @ghost_list.map {|x| Ruport::Data::Record.new x }
|
10
|
-
@ghost_collection = Ruport::Data::Collection.new @ghost_records
|
11
|
-
@ghost_table = Ruport::Data::Table.new :data => @ghost_list
|
12
|
-
@ghost_set = Ruport::Data::Set.new :data => @ghost_list
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_size
|
16
|
-
assert_equal 3, @ghosts.length
|
17
|
-
assert_equal @ghosts.length, @ghosts.data.length
|
18
|
-
assert_equal @ghosts.length, @ghosts.size
|
19
|
-
assert_equal @ghosts.length, @ghosts.data.size
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_to_table
|
23
|
-
assert_equal @ghost_table, @ghost_collection.to_table
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_to_set
|
27
|
-
assert_equal @ghost_set, @ghost_collection.to_set
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/test_set.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require "ruport"
|
5
|
-
|
6
|
-
class TestSet < Test::Unit::TestCase
|
7
|
-
include Ruport::Data
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@empty_set = Set.new
|
11
|
-
@set = Set.new :data => [%w[shirt box onion]]
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_constructor
|
15
|
-
assert_not_nil @empty_set
|
16
|
-
|
17
|
-
assert_not_nil @set
|
18
|
-
assert_not_nil @set.data
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_set_is_a_collection
|
22
|
-
assert_kind_of Ruport::Data::Collection, @set
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_equality
|
26
|
-
assert_equal @set, Set.new(:data => [%w[shirt box onion]])
|
27
|
-
assert_not_equal @set, Set.new(:data => [%w[hat bucket turnip]])
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_append_record
|
31
|
-
s = Set.new
|
32
|
-
assert s.data.empty?
|
33
|
-
s << Record.new([1,2,3])
|
34
|
-
assert_equal [Record.new([1,2,3])], s.data.to_a
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_append_array
|
38
|
-
s = Set.new
|
39
|
-
assert s.data.empty?
|
40
|
-
s << [1,2,3]
|
41
|
-
assert_equal [Record.new([1,2,3])], s.data.to_a
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_dup
|
45
|
-
assert_not_equal @set.data.object_id, @set.dup.data.object_id
|
46
|
-
end
|
47
|
-
# def test_append_hash
|
48
|
-
# s = Set.new
|
49
|
-
# assert s.data.empty?
|
50
|
-
# s << {:a => 1, :b => 2, :c => 3}
|
51
|
-
# assert_equal [Record.new([1,2,3], :attributes => [:a,:b,:c])], s.data.to_a
|
52
|
-
# end
|
53
|
-
|
54
|
-
def test_union
|
55
|
-
set = Set.new
|
56
|
-
set << %w[ a b c ] << %w[ x y z ]
|
57
|
-
|
58
|
-
set2 = Set.new
|
59
|
-
set2 << %w[ a b c ] << ["d","","e"]
|
60
|
-
|
61
|
-
set3 = set | set2
|
62
|
-
assert_kind_of(Set, set3)
|
63
|
-
assert_equal(set3.data.length, 3)
|
64
|
-
assert_equal(Set.new(:data => [ %w[a b c], %w[x y z], ["d","","e"] ]), set3)
|
65
|
-
assert_equal((set | set2), set.union(set2))
|
66
|
-
assert_equal((set | set2), set + (set2))
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_difference
|
70
|
-
set = Set.new
|
71
|
-
set << %w[ a b c ] << %w[x y z] << [1,2,3]
|
72
|
-
|
73
|
-
set2 = Set.new
|
74
|
-
set2 << %w[ a b c ]
|
75
|
-
|
76
|
-
set3 = set - set2
|
77
|
-
assert_kind_of(Set, set3)
|
78
|
-
assert_equal(2, set3.data.length)
|
79
|
-
assert_equal(Set.new(:data => [ %w[x y z], [1,2,3] ]), set3)
|
80
|
-
assert_equal((set - set2), set.difference(set2))
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_intersection
|
84
|
-
set = Set.new
|
85
|
-
set << %w[ a b c ] << %w[x y z] << [1,2,3]
|
86
|
-
|
87
|
-
set2 = Set.new
|
88
|
-
set2 << %w[ a b c ]
|
89
|
-
|
90
|
-
set3 = set & set2
|
91
|
-
assert_kind_of(Set, set3)
|
92
|
-
assert_equal(1, set3.data.length)
|
93
|
-
assert_equal(Set.new(:data => [ %w[a b c] ]), set3)
|
94
|
-
assert_equal((set & set2), set.intersection(set2))
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_exclusion
|
98
|
-
set = Set.new
|
99
|
-
set << %w[ a b c ] << %w[x y z] << [1,2,3]
|
100
|
-
|
101
|
-
set2 = Set.new
|
102
|
-
set2 << %w[ a b c ]
|
103
|
-
|
104
|
-
set3 = set ^ set2
|
105
|
-
assert_kind_of(Set, set3)
|
106
|
-
assert_equal(2, set3.data.length)
|
107
|
-
assert_equal(Set.new(:data => [ %w[x y z], [1,2,3] ]), set3)
|
108
|
-
end
|
109
|
-
|
110
|
-
# sets only hold one of any item, so adding again does nothing
|
111
|
-
def test_set_semantics
|
112
|
-
set = Set.new
|
113
|
-
set << %w[ a b c]
|
114
|
-
set2 = set.dup
|
115
|
-
set2 << %w[ a b c]
|
116
|
-
assert_equal set, set2
|
117
|
-
end
|
118
|
-
end
|