Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Examples of formatting based on row

  • Loading branch information...
commit ef77d3303ee0d6acdbc07b05369fab12ab1b1f85 1 parent af15c55
Nathan Long authored
View
12 README.markdown
@@ -93,6 +93,18 @@ end
The built-in `ReportsController` uses this formatting when rendering the HTML and JSON representations, but not when rendering the CSV.
+If your formatting method takes a second argment, it will be given a hash of the values in the row.
+
+```ruby
+class MoneyLaunderingReport < Dossier::Report
+ #...
+ def format_payment(value, row)
+ return "$0.00" if row[:recipient] == 'Jimmy The Squid'
+ formatter.number_to_currency(value)
+ end
+end
+```
+
## Report Options and Footers
You may want to specify parameters for a report: which columns to show, a range of dates, etc. Dossier supports this via URL parameters, anything in `params[:options]` will be passed into your report's `initialize` method and made available via the `options` reader.
View
2  spec/fixtures/reports/employee.html
@@ -25,7 +25,7 @@
<td>3</td>
<td>Employee Elise Elderberry</td>
<td>Corporate Malfeasance</td>
-<td>$99,000.00</td>
+<td>Who's Asking?</td>
<td>No</td>
<td>2013-01-11</td>
</tr>
View
2  spec/fixtures/reports/employee_with_footer.html
@@ -25,7 +25,7 @@
<td>3</td>
<td>Employee Elise Elderberry</td>
<td>Corporate Malfeasance</td>
-<td>$99,000.00</td>
+<td>Who's Asking?</td>
<td>No</td>
<td>2013-01-11</td>
</tr>
View
5 spec/support/reports/employee.rb
@@ -55,8 +55,9 @@ def names
@names ||= options.fetch(:names) { [] }.dup
end
- def format_salary(amount)
- formatter.number_to_currency(amount) # unless format.csv?
+ def format_salary(amount, row)
+ return "Who's Asking?" if row[:division] == "Corporate Malfeasance"
+ formatter.number_to_currency(amount)
end
def format_hired_on(date)
Please sign in to comment.
Something went wrong with that request. Please try again.