Module: Gitter::Pivot

Included in:
PivotGrid
Defined in:
lib/gitter/pivot.rb

Instance Method Summary collapse

Instance Method Details

#cell(&cell) ⇒ Object



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

def cell &cell 
  if cell
    @cell ||= cell
  else
    @cell or raise ConfigurationError, 'undefined cell'
  end
end

#columnsObject



55
56
57
# File 'lib/gitter/pivot.rb', line 55

def columns
  @columns ||= x_axis.titles.map{|x|Column.new self, x} 
end

#drill_down(*names) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gitter/pivot.rb', line 43

def drill_down *names
  if names.present?
    @drill_down ||= facet_for names
  else
    @drill_down ||= @filters.keys
  end
end

#drill_down_facetsObject

returns [ down, current, ups ]



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gitter/pivot.rb', line 79

def drill_down_facets
  drill = drill_down.reverse
  i = drill.find_index{|f|f.selected?}
  if i == 0
    down = nil
	current, *ups = drill[0..-1]
  else
    down, current, *ups = drill[i-1..-1]
  end

  [ down, current, ups ]
end

#header_rowsObject



59
60
61
62
63
64
65
# File 'lib/gitter/pivot.rb', line 59

def header_rows
  @header_rows ||= begin
    row = [''] + x_axis.titles
    row = row.map{|h|Gitter::Header.new self, h}
    [row]
  end
end

#input_tagsObject



51
52
53
# File 'lib/gitter/pivot.rb', line 51

def input_tags
  []
end

#pivot_cells(*groups) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gitter/pivot.rb', line 5

def pivot_cells *groups
  opts = groups.extract_options!
  sum = opts[:sum]
  count = opts[:count]; count = :id if count == true

  groups = [groups].flatten

  cells = self.scope
  groups.each{ |g| cells = cells.group(g)}
  cells = cells.sum(sum) if sum
  cells = cells.count(:id) if count
  cells
end

#rows(scope = self.scope) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/gitter/pivot.rb', line 67

def rows scope = self.scope
  y_axis.data_titles.map do |y,y_title|
    row = []
    row << Gitter::Cell.new(y_title)
    row += x_axis.data.map do |x|
      content = cell.call data_scope, x, y
      Gitter::Cell.new content
    end
  end
end

#x_axis(*args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/gitter/pivot.rb', line 19

def x_axis *args
  if args.present?
    @x_axis = Axis.new self, *args 
  else
    @x_axis or raise ConfigurationError, 'undefined x_axis'
  end
end

#y_axis(*args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gitter/pivot.rb', line 27

def y_axis *args
  if args.present?
    @y_axis = Axis.new self, *args 
  else
    @y_axis or raise ConfigurationError, 'undefined y_axis'
  end
end