Class: SirTracksAlot::Reports::FilterReport
- Inherits:
-
SirTracksAlotReport
- Object
- Ruport::Controller
- Report
- SirTracksAlotReport
- SirTracksAlot::Reports::FilterReport
- Defined in:
- lib/sir_tracks_alot/reports/filter_report.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Helpers Classes: HTML
Constant Summary collapse
- COLUMN_NAMES =
['title', 'page views', 'visits']
Instance Attribute Summary
Attributes inherited from SirTracksAlotReport
Attributes inherited from Report
Instance Method Summary collapse
-
#setup ⇒ Object
Build up reports by filtering things.
Methods inherited from Report
Instance Method Details
#setup ⇒ Object
Build up reports by filtering things. Filters are applied and assigned a row title.
:filters =
'Title' => {:category => 'category', :target => /\/categories/
}
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sir_tracks_alot/reports/filter_report.rb', line 15 def setup super counts = {} .filters ||= {} .column_names ||= COLUMN_NAMES .filters.each do |title, | Count.filter(.merge(:owner => .owner)).each do |count| count.summaries.each do |summary| counts[title] ||= [0,0] counts[title][0] += summary.visits.to_i counts[title][1] += summary.views.to_i end end end table = Table(.column_names) do |t| counts.each do |title, n| t << [title, n[0], n[1]] end end table.sort_rows_by!('page views', :order => :descending) self.data = table end |