Class ReportsHelper::ReportYear
In: app/helpers/reports_helper.rb
Parent: Object

Helper class for reporthelp_week_selection and reporthelp_month_selection. Initialize by passing a year for a full set of months, or by passing a year and a range of accurate dates. If the year matches the first or last date in that range, then the months associated with the year will be restricted according to the matching start and/or end date. The range, if given, MUST have a "first" date which is earlier in the year, or at worst the same date as the "last" date (i.e. don‘t pass in "backwards" ranges).

Commercial numbered weeks within which a given date falls may start or end on the previous or next year. If the caller provides a limiting date range that exhibits this (e.g. passes in 31st December 2008, which actually lies in week 1, 2009) then the ReportYear object can do nothing other than represent a full set of its own numbered weeks. If you want to create an object for the extra year, where applicable, you must do so manually.

Methods

new  

Attributes

months  [R] 
title  [R] 
weeks  [R] 

Public Class methods

[Source]

     # File app/helpers/reports_helper.rb, line 55
 55:     def initialize( year, date_range = nil )
 56:       @title  = year.to_s
 57:       @weeks  = []
 58:       @months = []
 59: 
 60:       # "limit" is set if the object is being built for the current year.
 61:       # Weeks and months are checked and any that lie in the future are
 62:       # not included.
 63: 
 64:       today = Date.current
 65:       limit = ( year == today.year )
 66:       range = ( 1..( Timesheet.get_last_week_number( year ) ) )
 67: 
 68:       # Work out the weeks, limited as above, or perhaps by an optional date
 69:       # range passed in by the caller.
 70: 
 71:       range.each do | week |
 72:         first_day_of_week = Timesheet.date_for( year, week, TimesheetRow::FIRST_DAY, true )
 73:         last_day_of_week  = first_day_of_week + 6
 74: 
 75:         break if (
 76:           ( limit      and first_day_of_week > today           ) or
 77:           ( date_range and first_day_of_week > date_range.last )
 78:         )
 79: 
 80:         next if (
 81:           ( date_range and last_day_of_week < date_range.first )
 82:         )
 83: 
 84:         @weeks.unshift( ReportWeek.new( year, week ) )
 85:       end
 86: 
 87:       # Work out hte months, again limited as above.
 88: 
 89:       ( 1..12 ).each do | month |
 90: 
 91:         break if (
 92:           ( limit      and month > today.month           ) or
 93:           ( date_range and month > date_range.last.month and date_range.last.year == year )
 94:         )
 95: 
 96:         next if (
 97:           ( date_range and month < date_range.first.month and date_range.first.year == year  )
 98:         )
 99: 
100:         @months.unshift( ReportMonth.new( year, month ) )
101:       end
102:     end

[Validate]