Prev | Current Page 208 | Next

David Berube

"Practical Reporting with Ruby and Rails"

The code then sums all of those transactions and returns the value to the
outer query.
The WEEKDAY function is used to determine whether a given transaction occurs on a
weekend or a weekday. If the WEEKDAY function returns a 6 or a 7??”that is, Saturday or
Sunday??”it??™s a weekend transaction.
The COALESCE function returns its first non-null argument. It is used to ensure you
return a zero rather than a null if there was no spending.
CHAPTER 7 n TRACKING EXPENDITURES WITH PAYPAL 150
DETERMINING A WEEKEND DATE IN RUBY
If you need to determine whether a given date is a weekend in Ruby, you can use the following code to
do just that:
class Date
def is_weekend?
self.cwday == 6 or self.cwday == 7 # If it's a Saturday or a Sunday,
# it's a weekend.
end
end
This code extends the Date class to have an additional method, is_weekend?, which returns
true if the given date is on a weekend and false otherwise.
Next, you loop through your results and convert them into an array of data suitable
for graphing:
weeks = []
max_gross=0.


Pages:
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
Moody Blues gry na gba Angela McCluskey Malcolm McLaren Mary Mary