0
PaypalTransaction.find_by_sql(sql).each do |week|
max_gross = week.weekday_amount.to_f if week.weekday_amount.to_f > max_gross
max_gross = week.weekend_amount.to_f if week.weekend_amount.to_f > max_gross
weeks << { :week_number=>week.week_number.to_i,
:year=>week.year.to_i,
:weekday_amount=>week.weekday_amount.to_f,
:weekend_amount=>week.weekend_amount.to_f
}
end
This loop handles two issues: first, you can track the highest value, which will be
used to scale your graph. Next, an element is appended to the weeks array, which contains
your data cast to an appropriate type: integer or float. (Without this cast, the variables
would be returned as strings.) This array will be used next to produce an HTML page with
a list of weeks and a graph.
CHAPTER 7 n TRACKING EXPENDITURES WITH PAYPAL 151
The HTML page is produced using Markaby. The first part of the code that uses
Markaby is as follows:
mab = Markaby::Builder.new() do
html do
head do
title 'PayPal Spending Report'
style :type => "text/css" do %[
.
Pages:
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221