Class: DoubleEntry::Reporting::WeekRange Private
- Defined in:
- lib/double_entry/reporting/week_range.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
We use a particularly crazy week numbering system: week 1 of any given year is the first week with any days that fall into that year.
So, for example, week 1 of 2011 starts on 27 Dec 2010.
Instance Attribute Summary collapse
- #week ⇒ Object readonly private
- #year ⇒ Object readonly private
Attributes inherited from TimeRange
#day, #finish, #hour, #month, #range_type, #start
Class Method Summary collapse
- .current ⇒ Object private
- .from_time(time) ⇒ Object private
-
.reportable_weeks(options = {}) ⇒ Array<WeekRange>
private
Obtain a sequence of WeekRanges from the given start to the current week.
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #all_time ⇒ Object private
-
#initialize(options = {}) ⇒ WeekRange
constructor
private
A new instance of WeekRange.
- #next ⇒ Object private
- #previous ⇒ Object private
- #to_s ⇒ Object private
Methods inherited from TimeRange
#human_readable_name, #include?, #key, make, range_from_time_for_period
Constructor Details
#initialize(options = {}) ⇒ WeekRange
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of WeekRange.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/double_entry/reporting/week_range.rb', line 53 def initialize( = {}) super if .present? @week = [:week] @start = week_and_year_to_time(@week, @year) @finish = @start.end_of_week @start = earliest_week.start if [:range_type] == :all_time end end |
Instance Attribute Details
#week ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/double_entry/reporting/week_range.rb', line 51 def week @week end |
#year ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/double_entry/reporting/week_range.rb', line 51 def year @year end |
Class Method Details
.current ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/double_entry/reporting/week_range.rb', line 19 def current from_time(Time.now) end |
.from_time(time) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 |
# File 'lib/double_entry/reporting/week_range.rb', line 12 def from_time(time) time = time.to_time if time.is_a? Date year = time.end_of_week.year week = ((time.beginning_of_week - start_of_year(year)) / 1.week).floor + 1 new(:year => year, :week => week) end |
.reportable_weeks(options = {}) ⇒ Array<WeekRange>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Obtain a sequence of WeekRanges from the given start to the current week.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/double_entry/reporting/week_range.rb', line 29 def reportable_weeks( = {}) week = [:from] ? from_time([:from]) : earliest_week last_in_sequence = self.current [week].tap do |weeks| while week != last_in_sequence week = week.next weeks << week end end end |
Instance Method Details
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/double_entry/reporting/week_range.rb', line 74 def ==(other) (self.week == other.week) && (self.year == other.year) end |
#all_time ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/double_entry/reporting/week_range.rb', line 78 def all_time self.class.new(:year => year, :week => week, :range_type => :all_time) end |
#next ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/double_entry/reporting/week_range.rb', line 70 def next from_time(@start + 1.week) end |
#previous ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/double_entry/reporting/week_range.rb', line 66 def previous from_time(@start - 1.week) end |
#to_s ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/double_entry/reporting/week_range.rb', line 82 def to_s "#{year}, Week #{week}" end |