Class: Munger::Report
- Inherits:
-
Object
- Object
- Munger::Report
- Defined in:
- lib/munger/report.rb
Instance Attribute Summary collapse
- #aggregate(values = nil) ⇒ Object
-
#column_data_fields ⇒ Object
Returns the value of attribute column_data_fields.
-
#column_formatters ⇒ Object
Returns the value of attribute column_formatters.
-
#column_titles ⇒ Object
Returns the value of attribute column_titles.
- #columns(values = nil) ⇒ Object
-
#data ⇒ Object
writeonly
Sets the attribute data.
-
#grouping_level ⇒ Object
readonly
Returns the value of attribute grouping_level.
-
#process_data ⇒ Object
readonly
Returns the value of attribute process_data.
- #sort(values = nil) ⇒ Object
- #subgroup(values = nil, options = {}) ⇒ Object
-
#subgroup_options ⇒ Object
writeonly
Sets the attribute subgroup_options.
Class Method Summary collapse
Instance Method Summary collapse
- #column_data_field(column) ⇒ Object
- #column_formatter(column) ⇒ Object
- #column_title(column) ⇒ Object
-
#get_subgroup_rows(group_level = nil) ⇒ Object
post-processing calls.
-
#initialize(options = {}) ⇒ Report
constructor
r = Munger::Report.new ( :data => data, :columns => [:collect_date, :spot_name, :airings, :display_name], :sort => [:collect_date, :spot_name] :subgroup => @group_list, :aggregate => => new_columns ) report = r.highlight.
-
#process(options = {}) ⇒ Object
returns ReportTable.
- #processed? ⇒ Boolean
- #rows ⇒ Object
- #set_options(options) ⇒ Object
-
#style_cells(style, options = {}) ⇒ Object
@report.style_cells(‘highlight’) { |cell, row| cell > 32 }.
-
#style_rows(style, options = {}) ⇒ Object
@report.style_rows(‘highlight’) { |row| row.age > 32 }.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Report
r = Munger::Report.new ( :data => data,
:columns => [:collect_date, :spot_name, :airings, :display_name],
:sort => [:collect_date, :spot_name]
:subgroup => @group_list,
:aggregate => {:sum => new_columns} )
report = r.highlight
15 16 17 18 19 20 21 |
# File 'lib/munger/report.rb', line 15 def initialize( = {}) @grouping_level = 0 @column_titles = {} @column_data_fields = {} @column_formatters = {} () end |
Instance Attribute Details
#aggregate(values = nil) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/munger/report.rb', line 111 def aggregate(values = nil) if values @aggregate = values self else @aggregate end end |
#column_data_fields ⇒ Object
Returns the value of attribute column_data_fields.
6 7 8 |
# File 'lib/munger/report.rb', line 6 def column_data_fields @column_data_fields end |
#column_formatters ⇒ Object
Returns the value of attribute column_formatters.
6 7 8 |
# File 'lib/munger/report.rb', line 6 def column_formatters @column_formatters end |
#column_titles ⇒ Object
Returns the value of attribute column_titles.
6 7 8 |
# File 'lib/munger/report.rb', line 6 def column_titles @column_titles end |
#columns(values = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/munger/report.rb', line 81 def columns(values = nil) if values if values.is_a? Hash @columns = values.keys @column_titles = values else @columns = Data.array(values) end self else @columns ||= @data.columns end end |
#data=(value) ⇒ Object (writeonly)
Sets the attribute data
5 6 7 |
# File 'lib/munger/report.rb', line 5 def data=(value) @data = value end |
#grouping_level ⇒ Object (readonly)
Returns the value of attribute grouping_level.
7 8 9 |
# File 'lib/munger/report.rb', line 7 def grouping_level @grouping_level end |
#process_data ⇒ Object (readonly)
Returns the value of attribute process_data.
7 8 9 |
# File 'lib/munger/report.rb', line 7 def process_data @process_data end |
#sort(values = nil) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/munger/report.rb', line 62 def sort(values = nil) if values @sort = values self else @sort end end |
#subgroup(values = nil, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/munger/report.rb', line 71 def subgroup(values = nil, = {}) if values @subgroup = values @subgroup_options = self else @subgroup end end |
#subgroup_options=(value) ⇒ Object (writeonly)
Sets the attribute subgroup_options
5 6 7 |
# File 'lib/munger/report.rb', line 5 def (value) @subgroup_options = value end |
Class Method Details
Instance Method Details
#column_data_field(column) ⇒ Object
103 104 105 |
# File 'lib/munger/report.rb', line 103 def column_data_field(column) @column_data_fields[column] || column.to_s end |
#column_formatter(column) ⇒ Object
107 108 109 |
# File 'lib/munger/report.rb', line 107 def column_formatter(column) @column_formatters[column] end |
#column_title(column) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/munger/report.rb', line 95 def column_title(column) if c = @column_titles[column] return c.to_s else return column.to_s end end |
#get_subgroup_rows(group_level = nil) ⇒ Object
post-processing calls
167 168 169 170 171 |
# File 'lib/munger/report.rb', line 167 def get_subgroup_rows(group_level = nil) data = @process_data.select { |r| r[:meta][:group] } data = data.select { |r| r[:meta][:group] == group_level } if group_level data end |
#process(options = {}) ⇒ Object
returns ReportTable
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/munger/report.rb', line 50 def process( = {}) () # sorts and fills NativeReport @report = translate_native(do_field_sort(@data.data)) do_add_groupings do_add_aggregate_rows self end |
#processed? ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/munger/report.rb', line 41 def processed? if @process_data true else false end end |
#rows ⇒ Object
120 121 122 |
# File 'lib/munger/report.rb', line 120 def rows @process_data.size end |
#set_options(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/munger/report.rb', line 27 def () if d = [:data] if d.is_a? Munger::Data @data = d else @data = Munger::Data.new(:data => d) end end self.sort([:sort]) if [:sort] self.columns([:columns]) if [:columns] self.subgroup([:subgroup]) if [:subgroup] self.aggregate([:aggregate]) if [:aggregate] end |
#style_cells(style, options = {}) ⇒ Object
@report.style_cells(‘highlight’) { |cell, row| cell > 32 }
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/munger/report.rb', line 129 def style_cells(style, = {}) @process_data.each_with_index do |row, index| # filter columns to look at if [:only] cols = Data.array([:only]) elsif [:except] cols = columns - Data.array([:except]) else cols = columns end if [:no_groups] && row[:meta][:group] next end cols.each do |col| if yield(row[:data][col], row[:data]) @process_data[index][:meta][:cell_styles] ||= {} @process_data[index][:meta][:cell_styles][col] ||= [] @process_data[index][:meta][:cell_styles][col] << style end end end end |
#style_rows(style, options = {}) ⇒ Object
@report.style_rows(‘highlight’) { |row| row.age > 32 }
156 157 158 159 160 161 162 163 |
# File 'lib/munger/report.rb', line 156 def style_rows(style, = {}) @process_data.each_with_index do |row, index| if yield(row[:data]) @process_data[index][:meta][:row_styles] ||= [] @process_data[index][:meta][:row_styles] << style end end end |
#to_s ⇒ Object
173 174 175 |
# File 'lib/munger/report.rb', line 173 def to_s pp @process_data end |