Class: Crosstab::Column

Inherits:
Generic show all
Defined in:
lib/crosstab/column.rb

Instance Method Summary collapse

Methods inherited from Generic

#printed?, #qualification, #qualifies?, #title

Constructor Details

#initialize(label = nil, qual = nil) ⇒ Column

Returns a new instance of Column.



2
3
4
5
# File 'lib/crosstab/column.rb', line 2

def initialize(label=nil, qual=nil)    
  title label if label
  qualification qual if qual
end

Instance Method Details

#group(g = nil) ⇒ Object

DSL accessor for the group attribute

Example:

group
# => nil

group Crosstab::Group.new("Gender")
# => Crosstab::Group...

group.title
# => "Gender"


56
57
58
59
60
61
62
63
# File 'lib/crosstab/column.rb', line 56

def group(g=nil)
  if g
    @group = g
    g.children << self # Add self to its list of children
  else        
    @group ||= nil
  end
end

#records(value = nil) ⇒ Object

attr_reader for the records attribute which should contain an empty array, or – if calculate was called on the crosstab – this will contain the array of records that fit this column’s qualification.

Example:

my_crosstab = Crosstab::Crosstab.new do
  data_source [{:a => 1, :b => 1}, {:a => 2, :b => 2}]

  banner do
    title "Age"
    column "18-34", :b => 1
    column "35-54", :b => 2
  end

  table do
    row "Male", :a => 1
    row "Female", :a => 2
  end
end

my_crosstab.calculate

my_crosstab.banner.columns[0].title
# => "18-34"

my_crosstab.banner.columns[0].records
# => [{:a => 1, :b => 1}]


35
36
37
38
39
40
41
# File 'lib/crosstab/column.rb', line 35

def records(value=nil)
  if value
    @records = value
  else
    @records ||= []
  end
end