Permalink
Browse files

added in create_rag_group

git-svn-id: http://stonecode.svnrepository.com/svn/ruport/trunk@296 bb2e8eb0-7117-0410-aac4-c024b40ed5f7
  • Loading branch information...
1 parent 6144702 commit 010053201a118717afcea1b444a9c54c2f1ae144 sandal committed Oct 21, 2006
@@ -19,6 +19,6 @@ class GraphSample < Ruport::Report
end
end
-GraphSample.run { |r| puts r.write }
+GraphSample.run(:tries => 3, :timeout => 1) { |r| sleep 2; puts r.results }
View
@@ -65,6 +65,6 @@ def self.configure(&block)
end
-%w[attempt config meta_tools report format query data mailer].each { |lib|
+%w[attempt config data meta_tools report format query mailer].each { |lib|
require "ruport/#{lib}"
}
View
@@ -52,7 +52,6 @@ def attempt
if @tries > 0
msg = "Error on attempt # #{count}: #{error}; retrying"
count += 1
- #warn msg if @warnings
Ruport.log(msg, :level => log_level)
@interval += @increment if @increment
sleep @interval
View
@@ -1 +1 @@
-%w[taggable record collection table set groupable ].each { |l| require "ruport/data/#{l}" }
+%w[groupable taggable record collection table set].each { |l| require "ruport/data/#{l}" }
@@ -1,11 +1,17 @@
module Ruport::Data
module Groupable
+
def group_by_tag
r_tags = data.map {|row| row.tags}.flatten.uniq
d = r_tags.map do |t|
- select {|row| row.tags.include? t }.to_table(column_names)
+ select {|row| row.tags.include? t }.to_table(column_names)
end
Record.new d, :attributes => r_tags
end
+
+ def create_tag_group(label,&block)
+ select(&block).each { |r| r.tag label }
+ end
+
end
end
View
@@ -33,7 +33,7 @@ module Ruport::Data
#
# For building a table using ActiveRecord, have a look at Ruport::Reportable.
class Table < Collection
-
+ include Groupable
# Creates a new table based on the supplied options.
# Valid options are :data and :column_names.
#
@@ -327,4 +327,12 @@ def sigma(column=nil)
alias_method :sum, :sigma
end
+
+end
+
+module Ruport::Data::TableHelper
+ def table(names=[])
+ t = [].to_table(names)
+ yield(t) if block_given?; t
+ end
end
View
@@ -11,6 +11,7 @@
require "forwardable"
module Ruport
+
# === Overview
#
# The Ruport::Report class povides a high level interface to most of Ruport's
@@ -71,6 +72,7 @@ module Ruport
class Report
extend Forwardable
+ include Ruport::Data::TableHelper
# When initializing a report, you can provide a default mailer and source by
# giving a name of a valid source or mailer you've defined via
# Ruport::Config
@@ -183,7 +185,7 @@ def process_text(string, options)
#
# E.g
#
- # text_processor(:unix_newlines) { results.gsub!(/\r\n/,"\n") }
+ # text_processor(:unix_newlines) { |r| r.gsub(/\r\n/,"\n") }
def text_processor(label,&block)
Format.register_filter(label, &block)
end
View
@@ -25,6 +25,17 @@ def test_simple
:attributes => ["foo","bar"] )
assert_equal expected, a.group_by_tag
end
+
+ def test_create_tag_group
+ a = [[1,2,3],[4,5,6],[7,8,9]].to_table(%w[a b c])
+ expected = Ruport::Data::Record.new( [ [[1,2,3],[7,8,9]].to_table(%w[a b c]),
+ [[4,5,6]].to_table(%w[a b c]) ],
+ :attributes => %w[starts_odd starts_even])
+ a.create_tag_group(:starts_odd) { |r| (r[0] % 2) != 0 }
+ a.create_tag_group(:starts_even) { |r| (r[0] % 2).zero? }
+
+ assert_equal expected, a.group_by_tag
+ end
end
View
@@ -294,6 +294,17 @@ def test_ensure_coerce_sum
end
+ def test_table_shortcut
+ self.class.send(:include,Ruport::Data::TableHelper)
+
+ a = table(%w[a b c]) do |t|
+ [[1,2,3],[4,5,6]].each { |r| t << r }
+ end
+
+ assert_equal([[1,2,3],[4,5,6]].to_table(%w[a b c]),a)
+
+ end
+
def test_setting_column_names_changes_record_attributes
table = Ruport::Data::Table.new :column_names => %w[a b c],
:data => [[1,2,3],[4,5,6]]

0 comments on commit 0100532

Please sign in to comment.