Module: Kernel
- Defined in:
- lib/ruport/data/table.rb,
lib/ruport/data/grouping.rb
Instance Method Summary collapse
-
#Group(name, opts = {}) ⇒ Object
Shortcut interface for creating Data::Group.
-
#Grouping(*args) ⇒ Object
Shortcut interface for creating Data::Grouping.
-
#Table(*args, &block) ⇒ Object
Shortcut interface for creating Data::Tables.
Instance Method Details
#Group(name, opts = {}) ⇒ Object
Shortcut interface for creating Data::Group
Example:
g = Group('mygroup', :data => [[1,2,3],[4,5,6]],
:column_names => %w[a b c]) #=> creates a new group named mygroup
396 397 398 |
# File 'lib/ruport/data/grouping.rb', line 396 def Group(name,opts={}) Ruport::Data::Group.new(opts.merge(:name => name)) end |
#Grouping(*args) ⇒ Object
Shortcut interface for creating Data::Grouping
Example:
a = Table(%w[a b c], :data => [[1,2,3],[4,5,6]])
b = Grouping(a, :by => "a") #=> creates a new grouping on column "a"
385 386 387 |
# File 'lib/ruport/data/grouping.rb', line 385 def Grouping(*args) Ruport::Data::Grouping.new(*args) end |
#Table(*args, &block) ⇒ Object
Shortcut interface for creating Data::Tables
Examples:
t = Table(%w[a b c]) #=> creates a new empty table w. cols a,b,c
t = Table("a","b","c") #=> creates a new empty table w. cols a,b,c
# allows building table inside of block, returns table object
t = Table(%w[a b c]) { |t| t << [1,2,3] }
# allows loading table from CSV
# accepts all Data::Table.load options, including block (yields table,row)
t = Table("foo.csv")
t = Table("bar.csv", :has_names => false)
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
# File 'lib/ruport/data/table.rb', line 928 def Table(*args,&block) table= case(args[0]) when Array opts = args[1] || {} Ruport::Data::Table.new(f={:column_names => args[0]}.merge(opts),&block) when /\.csv/ return Ruport::Data::Table.load(*args,&block) when Hash if file = args[0].delete(:file) return Ruport::Data::Table.load(file,args[0],&block) elsif string = args[0].delete(:string) return Ruport::Data::Table.parse(string,args[0],&block) else return Ruport::Data::Table.new(args[0],&block) end else Ruport::Data::Table.new(:data => [], :column_names => args,&block) end return table end |