Module: QueryReport::Record
- Included in:
- Report
- Defined in:
- lib/query_report/record.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #all_records ⇒ Object
- #all_records_to_render ⇒ Object
- #apply ⇒ Object
- #content_from_element(content) ⇒ Object
- #filtered_query ⇒ Object
- #has_any_rowspan? ⇒ Boolean
- #map_record(query, render_from_view) ⇒ Object
- #map_rowspan(recs) ⇒ Object
- #model_class ⇒ Object
- #paginated_query ⇒ Object
- #records ⇒ Object
- #records_to_render ⇒ Object
- #search ⇒ Object
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
3 4 5 |
# File 'lib/query_report/record.rb', line 3 def query @query end |
Instance Method Details
#all_records ⇒ Object
33 34 35 |
# File 'lib/query_report/record.rb', line 33 def all_records @all_records ||= map_record(filtered_query, false) end |
#all_records_to_render ⇒ Object
55 56 57 |
# File 'lib/query_report/record.rb', line 55 def all_records_to_render @all_records_to_render ||= map_rowspan(all_records) end |
#apply ⇒ Object
24 25 26 27 |
# File 'lib/query_report/record.rb', line 24 def apply @filtered_query ||= apply_filters(query.clone, @params) @paginated_query ||= apply_pagination(@filtered_query, @params) end |
#content_from_element(content) ⇒ Object
96 97 98 |
# File 'lib/query_report/record.rb', line 96 def content_from_element(content) content.kind_of?(Hash) ? content[:content] : content end |
#filtered_query ⇒ Object
9 10 11 12 |
# File 'lib/query_report/record.rb', line 9 def filtered_query apply @filtered_query end |
#has_any_rowspan? ⇒ Boolean
46 47 48 49 |
# File 'lib/query_report/record.rb', line 46 def has_any_rowspan? @has_any_rowspan = @columns.any?(&:rowspan?) if @has_any_rowspan.nil? @has_any_rowspan end |
#map_record(query, render_from_view) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/query_report/record.rb', line 37 def map_record(query, render_from_view) @columns = @columns.delete_if { |col| col.only_on_web? } unless render_from_view query.map do |record| array = @columns.collect { |column| [column.humanize, sanitize_value(column.value(record), render_from_view)] } Hash[*array.flatten] end end |
#map_rowspan(recs) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/query_report/record.rb', line 59 def map_rowspan(recs) return recs unless has_any_rowspan? last_reset_index = @columns.select(&:rowspan?).inject({}) { |hash, column| hash[column.humanize] = 0; hash } rowspan_column_hash = @columns.select(&:rowspan?).inject({}) { |hash, column| hash[column.humanize] = column.rowspan_column_humanized; hash } prev_row = {} recs.each_with_index do |row, index| last_reset_index.each do |col, last_index| rowspan_col = rowspan_column_hash[col] rowspan_content = content_from_element(row[rowspan_col]) #picking the current content of the rowspan column prev_rowspan_content = content_from_element(prev_row[rowspan_col]) #picking the last rowspan content stored content = row[col] prev_content = content_from_element(prev_row[col]) if index == 0 || rowspan_content != prev_rowspan_content || content != prev_content last_reset_index[col] = index #initialize row[col] = {content: content, rowspan: 1} elsif rowspan_content == prev_rowspan_content recs[last_index][col][:rowspan] += 1 end end prev_row = row end #cleaning up the un needed row values recs.each do |row| last_reset_index.each do |col, last_index| row.delete col unless row[col].kind_of?(Hash) end end end |
#model_class ⇒ Object
5 6 7 |
# File 'lib/query_report/record.rb', line 5 def model_class query.klass end |
#paginated_query ⇒ Object
14 15 16 17 |
# File 'lib/query_report/record.rb', line 14 def paginated_query apply @paginated_query end |
#records ⇒ Object
29 30 31 |
# File 'lib/query_report/record.rb', line 29 def records @records ||= map_record(paginated_query, true) end |
#records_to_render ⇒ Object
51 52 53 |
# File 'lib/query_report/record.rb', line 51 def records_to_render @records_to_render ||= map_rowspan(records) end |
#search ⇒ Object
19 20 21 22 |
# File 'lib/query_report/record.rb', line 19 def search apply @search end |