coryodaniel / skeleton

Super simple HTML table reports

This URL has Read+Write access

name age message
file CHANGELOG Loading commit data...
file README.markdown
file Rakefile
directory lib/
file skeleton.gemspec
directory spec/
directory tasks/
README.markdown

Skeleton is a super simply report generation and linking gem.

Usage

# gem sources -a http://gems.github.com
# gem install coryodaniel-skeleton 

require 'rubygems'
require 'skeleton'

# Create a report           
class FavoriteColorDetailedReport
  include Skeleton::Report

  report_name "Demographics for people that like %s"

  column :age
  column :gender
  column :location

  def initialize(color,people)
    report_name_addl << color
    people.each do |person|
      rows << Skeleton::Row.new({
        :age      => person.age,
        :gender   => person.gender,
        :location => person.location
      })
    end
  end
end

class FavoriteColorAggregateReport
  include Skeleton::Report

  report_name

  # Define the columns in your report
  column :color
  column :frequency
  column :details

  # create an constructor to set up your data
  def initialize
    color_data = %w(red orange yellow green blue purple black white brown grey)

    # for this example we'll pretend we have a DataMapper/ActiveRecord table containing the data
    color_data.each do |color|
      people = People.all(:favorite_color => color)

      # rows is an accessor for attaching rows to this report
      rows << Skeleton::Row.new({
        :color      => color,
        :frequency  => people.length, 
        # Attach a detailed report to the 'details' field.
        :details    => FavoriteColorDetailedReport.new(color, people)
      })

    end #end color_data loop

  end #end initialize
end

FavoriteColorAggregateReport.new.generate(:index => true) #:index makes it the index file.