ruport 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,20 @@
1
- Tnghe current version of Ruby Reports is 0.5.3
1
+ Tnghe current version of Ruby Reports is 0.5.4
2
+
3
+ changes since 0.5.3
4
+
5
+ - Fixed a bug where Table#<< would fail silently if an object could not be
6
+ converted to a Record
7
+
8
+ - Fixed a bug where setting column names after a table was initialized without
9
+ them caused Table to break.
10
+
11
+ - Example added for basic grouping functionality
12
+
13
+ - Table#column_names= reworked to address a performance concern.
14
+
15
+ - Collection#[] moved to Table#[], since Set#[] is not implemented.
16
+
17
+ - Quieted some warnings discovered by pat eyler
2
18
 
3
19
  changes since 0.5.2
4
20
 
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  spec = Gem::Specification.new do |spec|
25
25
  spec.name = LEAN ? "lean-ruport" : "ruport"
26
- spec.version = "0.5.3"
26
+ spec.version = "0.5.4"
27
27
  spec.platform = Gem::Platform::RUBY
28
28
  spec.summary = "A generalized Ruby report generation and templating engine."
29
29
  spec.files = Dir.glob("{examples,lib,test,bin}/**/**/**/*") +
@@ -0,0 +1,9 @@
1
+ require "ruport"
2
+ a = [ ['a',7],['b',5],['c',11],
3
+ ['d',9],['a',3],['b',2] ].to_table(%w[letter num])
4
+ puts "Initial Data:\n#{a}"
5
+ b = a.split(:group => "letter")
6
+ totals = [].to_table(%w[group sum])
7
+ b.attributes.each { |x| totals << [x,b[x].inject(0) { |s,r| s + r['num'] }] }
8
+ puts "After grouping:\n#{totals}"
9
+
@@ -12,7 +12,7 @@
12
12
 
13
13
  module Ruport
14
14
 
15
- VERSION = "0.5.3"
15
+ VERSION = "0.5.4"
16
16
 
17
17
  # Ruports logging and error interface.
18
18
  # Can generate warnings or raise fatal errors
@@ -40,12 +40,12 @@ module Ruport::Data
40
40
  # Provides a shortcut for the as() method by converting as(:format_name)
41
41
  # into to_format_name
42
42
  def method_missing(id,*args)
43
- return as($1.to_sym) if id.to_s =~ /^to_(.*)/
44
- super
43
+ return as($1.to_sym) if id.to_s =~ /^to_(.*)/
44
+ super
45
45
  end
46
46
 
47
47
  attr_reader :data
48
- def_delegators :@data, :each, :length, :size, :[], :empty?
48
+ def_delegators :@data, :each, :length, :size, :empty?
49
49
  end
50
50
  end
51
51
 
@@ -124,7 +124,7 @@ module Ruport::Data
124
124
  # Sets the attribute list for this Record
125
125
  #
126
126
  # my_record.attributes = %w[foo bar baz]
127
- def attributes=(a); @attributes=a; end
127
+ attr_writer :attributes
128
128
 
129
129
  # Allows you to change the order of or reduce the number of columns in a
130
130
  # Record. Example:
@@ -134,7 +134,7 @@ module Ruport::Data
134
134
  # b.attributes #=> ["a","d","b"]
135
135
  # b.data #=> [1,4,2]
136
136
  def reorder(*indices)
137
- dup.reorder! *indices
137
+ dup.reorder!(*indices)
138
138
  end
139
139
 
140
140
  # Same as Record#reorder but is destructive
@@ -47,14 +47,20 @@ module Ruport::Data
47
47
 
48
48
  attr_reader :column_names
49
49
 
50
+ def_delegator :@data, :[]
51
+
50
52
  # Sets the column names for this table. The single parameter should be
51
53
  # an array listing the names of the columns.
52
54
  #
53
55
  # tbl = Table.new({:data => [1,2,3], [3,4,5], :column_names => %w[a b c]})
54
56
  # tbl.column_names = %w[e f g]
55
57
  def column_names=(other)
56
- @column_names = other.dup
57
- map { |r| r.attributes = @column_names }
58
+ #FIXME: when column_names changes, we'll need to remove this
59
+ unless @column_names
60
+ @column_names = other.dup
61
+ each { |r| r.attributes = @column_names }
62
+ end
63
+ @column_names.replace(other.dup)
58
64
  end
59
65
 
60
66
  # Compares this table to another table and returns true if
@@ -88,13 +94,15 @@ module Ruport::Data
88
94
  when Array
89
95
  @data << Record.new(other, :attributes => @column_names)
90
96
  when Hash
91
- raise unless @column_names
97
+ raise ArgumentError unless @column_names
92
98
  arr = @column_names.map { |k| other[k] }
93
99
  @data << Record.new(arr, :attributes => @column_names)
94
100
  when Record
95
101
  raise ArgumentError unless column_names.eql? other.attributes
96
102
  @data << Record.new(other.data, :attributes => @column_names)
97
103
  @data.last.tags = other.tags.dup
104
+ else
105
+ raise ArgumentError
98
106
  end
99
107
  self
100
108
  end
@@ -104,6 +112,7 @@ module Ruport::Data
104
112
  #
105
113
  # data = Table.new({:data => [1,2], [3,4], :column_names => %w[a b]})
106
114
  # data.reorder!([1,0])
115
+ #
107
116
  def reorder!(*indices)
108
117
  indices = indices[0] if indices[0].kind_of? Array
109
118
  if @column_names
@@ -112,10 +121,12 @@ module Ruport::Data
112
121
  else
113
122
  indices
114
123
  end
124
+ # FIXME: @column_names.replace should and allow us to avoid the
125
+ # r.attributes hack below. This means this might be buggy.
115
126
  @column_names = x
116
127
  end
117
128
  @data.each { |r|
118
- r.reorder_data! *indices
129
+ r.reorder_data!(*indices)
119
130
  r.attributes = @column_names
120
131
  }; self
121
132
  end
@@ -125,7 +136,7 @@ module Ruport::Data
125
136
  # one = Table.new({:data => [1,2], [3,4], :column_names => %w[a b]})
126
137
  # two = one.reorder!([1,0])
127
138
  def reorder(*indices)
128
- dup.reorder! *indices
139
+ dup.reorder!(*indices)
129
140
  end
130
141
 
131
142
  # Adds an extra column to the table. Accepts an options Hash as its
@@ -103,7 +103,7 @@ module Ruport
103
103
  "no block given!", :status => :fatal,
104
104
  :level => :log_only, :exception => LocalJumpError
105
105
  ) unless action
106
- fetch &action
106
+ fetch(&action)
107
107
  end
108
108
 
109
109
  # Grabs the result set as a Data::Table or if in raw_data mode, an array of
@@ -15,6 +15,7 @@ class TestTable < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  a = Ruport::Data::Record.new [1,2,3]
18
+ assert a.respond_to?(:[])
18
19
  b = a.dup
19
20
  b.attributes = %w[col1 col2 col3]
20
21
  tables.zip([[],[],[a],[b]]).each { |t,n| assert_equal n, t.data }
@@ -28,6 +29,8 @@ class TestTable < Test::Unit::TestCase
28
29
  rec = table[0].dup
29
30
  rec.attributes = %w[a b c d]
30
31
  assert_raise(ArgumentError) { table << rec }
32
+ assert_raise(ArgumentError) { table << Object.new }
33
+ assert_raise(ArgumentError) { table << [].to_table }
31
34
  end
32
35
 
33
36
  def test_csv_load
@@ -110,3 +110,45 @@ F, [2006-09-14T15:43:03.220988 #2747] FATAL -- : no block given!
110
110
  F, [2006-09-14T15:44:57.026175 #2795] FATAL -- : Missing host for mailer bar
111
111
  F, [2006-09-14T15:44:57.027386 #2795] FATAL -- : Missing DSN for source foo!
112
112
  F, [2006-09-14T15:44:58.401789 #2795] FATAL -- : no block given!
113
+ F, [2006-09-15T22:15:33.543076 #2687] FATAL -- : Missing host for mailer bar
114
+ F, [2006-09-15T22:15:33.544463 #2687] FATAL -- : Missing DSN for source foo!
115
+ F, [2006-09-15T22:15:34.930062 #2687] FATAL -- : no block given!
116
+ F, [2006-09-15T22:38:15.020965 #2749] FATAL -- : Missing host for mailer bar
117
+ F, [2006-09-15T22:38:15.022562 #2749] FATAL -- : Missing DSN for source foo!
118
+ F, [2006-09-15T22:38:16.392428 #2749] FATAL -- : no block given!
119
+ F, [2006-09-16T12:16:28.334123 #3531] FATAL -- : Missing host for mailer bar
120
+ F, [2006-09-16T12:16:28.335300 #3531] FATAL -- : Missing DSN for source foo!
121
+ F, [2006-09-16T12:16:31.349294 #3531] FATAL -- : no block given!
122
+ F, [2006-09-22T10:57:48.979238 #2296] FATAL -- : Missing host for mailer bar
123
+ F, [2006-09-22T10:57:48.980766 #2296] FATAL -- : Missing DSN for source foo!
124
+ F, [2006-09-22T10:57:50.420679 #2296] FATAL -- : no block given!
125
+ F, [2006-09-22T11:28:10.025473 #2436] FATAL -- : Missing host for mailer bar
126
+ F, [2006-09-22T11:28:10.026722 #2436] FATAL -- : Missing DSN for source foo!
127
+ F, [2006-09-22T11:28:11.452947 #2436] FATAL -- : no block given!
128
+ F, [2006-09-22T11:29:34.369510 #2455] FATAL -- : Missing host for mailer bar
129
+ F, [2006-09-22T11:29:34.370692 #2455] FATAL -- : Missing DSN for source foo!
130
+ F, [2006-09-22T11:29:35.789372 #2455] FATAL -- : no block given!
131
+ F, [2006-09-22T12:22:11.125513 #2685] FATAL -- : Missing host for mailer bar
132
+ F, [2006-09-22T12:22:11.127121 #2685] FATAL -- : Missing DSN for source foo!
133
+ F, [2006-09-22T12:22:12.542014 #2685] FATAL -- : no block given!
134
+ F, [2006-09-22T12:24:39.561416 #2706] FATAL -- : Missing host for mailer bar
135
+ F, [2006-09-22T12:24:39.562607 #2706] FATAL -- : Missing DSN for source foo!
136
+ F, [2006-09-22T12:24:40.955523 #2706] FATAL -- : no block given!
137
+ F, [2006-09-22T12:25:58.299119 #2728] FATAL -- : Missing host for mailer bar
138
+ F, [2006-09-22T12:25:58.300290 #2728] FATAL -- : Missing DSN for source foo!
139
+ F, [2006-09-22T12:25:59.700961 #2728] FATAL -- : no block given!
140
+ F, [2006-09-22T12:26:20.389344 #2746] FATAL -- : Missing host for mailer bar
141
+ F, [2006-09-22T12:26:20.390526 #2746] FATAL -- : Missing DSN for source foo!
142
+ F, [2006-09-22T12:26:21.775565 #2746] FATAL -- : no block given!
143
+ F, [2006-09-22T12:28:27.008090 #2763] FATAL -- : Missing host for mailer bar
144
+ F, [2006-09-22T12:28:27.009264 #2763] FATAL -- : Missing DSN for source foo!
145
+ F, [2006-09-22T12:28:28.432881 #2763] FATAL -- : no block given!
146
+ F, [2006-09-23T20:49:21.609220 #3403] FATAL -- : Missing host for mailer bar
147
+ F, [2006-09-23T20:49:21.610861 #3403] FATAL -- : Missing DSN for source foo!
148
+ F, [2006-09-23T20:49:23.197684 #3403] FATAL -- : no block given!
149
+ F, [2006-09-23T20:50:04.754598 #3412] FATAL -- : Missing host for mailer bar
150
+ F, [2006-09-23T20:50:04.756157 #3412] FATAL -- : Missing DSN for source foo!
151
+ F, [2006-09-23T20:50:06.211906 #3412] FATAL -- : no block given!
152
+ F, [2006-09-23T20:50:29.074940 #3421] FATAL -- : Missing host for mailer bar
153
+ F, [2006-09-23T20:50:29.076482 #3421] FATAL -- : Missing DSN for source foo!
154
+ F, [2006-09-23T20:50:30.553625 #3421] FATAL -- : no block given!
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.3
7
- date: 2006-09-15 00:00:00 -04:00
6
+ version: 0.5.4
7
+ date: 2006-09-24 00:00:00 -04:00
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
10
  - lib
@@ -37,6 +37,7 @@ files:
37
37
  - examples/line_graph.rb
38
38
  - examples/report.rb
39
39
  - examples/long.txt
40
+ - examples/basic_grouping.rb
40
41
  - examples/simple_mail.rb
41
42
  - examples/template.rb
42
43
  - lib/ruport