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_with_rowspan ⇒ Object
- #apply ⇒ Object
- #filtered_query ⇒ Object
- #has_any_rowspan? ⇒ Boolean
- #map_record(query, render_from_view) ⇒ Object
- #map_rowspan(rec) ⇒ Object
- #model_class ⇒ Object
- #paginated_query ⇒ Object
- #records ⇒ Object
- #records_with_rowspan ⇒ 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_with_rowspan ⇒ Object
55 56 57 |
# File 'lib/query_report/record.rb', line 55 def all_records_with_rowspan @all_records_with_rowspan ||= 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 |
#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, column.value(record)] } Hash[*array.flatten] end end |
#map_rowspan(rec) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/query_report/record.rb', line 59 def map_rowspan(rec) last_reset_index = @columns.select(&:rowspan?).inject({}) { |hash, column| hash[column.humanize] = 0; hash } last_column_content = {} rec.each_with_index do |row, index| last_reset_index.each do |col, last_index| content = row[col] last_content = last_column_content[col] if index == 0 || content != last_content last_column_content[col] = content last_reset_index[col] = index #initialize row[col] = {content: content, rowspan: 1} elsif content == last_content rec[last_index][col][:rowspan] += 1 row.delete col end 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_with_rowspan ⇒ Object
51 52 53 |
# File 'lib/query_report/record.rb', line 51 def records_with_rowspan @records_with_rowspan ||= map_rowspan(records) end |
#search ⇒ Object
19 20 21 22 |
# File 'lib/query_report/record.rb', line 19 def search apply @search end |