Class: DoubleEntry::Reporting::MonthRange Private
- Defined in:
- lib/double_entry/reporting/month_range.rb
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.
Instance Attribute Summary collapse
- #month ⇒ Object readonly private
- #year ⇒ Object readonly private
Attributes inherited from TimeRange
#day, #finish, #hour, #range_type, #start, #week
Class Method Summary collapse
- .current ⇒ Object private
- .earliest_month ⇒ Object private
- .from_time(time) ⇒ Object private
-
.reportable_months(options = {}) ⇒ Array<MonthRange>
private
Obtain a sequence of MonthRanges from the given start to the current month.
Instance Method Summary collapse
- #<=>(other) ⇒ Object private
- #==(other) ⇒ Object private
- #all_time ⇒ Object private
- #beginning_of_financial_year ⇒ Object private
-
#initialize(options = {}) ⇒ MonthRange
constructor
private
A new instance of MonthRange.
- #next ⇒ Object (also: #succ) 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 = {}) ⇒ MonthRange
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 MonthRange.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/double_entry/reporting/month_range.rb', line 38 def initialize( = {}) super if .present? @month = [:month] month_start = Time.local(year, [:month], 1) @start = month_start @finish = month_start.end_of_month @start = MonthRange.earliest_month.start if [:range_type] == :all_time end end |
Instance Attribute Details
#month ⇒ 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.
36 37 38 |
# File 'lib/double_entry/reporting/month_range.rb', line 36 def month @month 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.
36 37 38 |
# File 'lib/double_entry/reporting/month_range.rb', line 36 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.
10 11 12 |
# File 'lib/double_entry/reporting/month_range.rb', line 10 def current from_time(Time.now) end |
.earliest_month ⇒ 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.
31 32 33 |
# File 'lib/double_entry/reporting/month_range.rb', line 31 def earliest_month from_time(Reporting.configuration.start_of_business) 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.
6 7 8 |
# File 'lib/double_entry/reporting/month_range.rb', line 6 def from_time(time) new(:year => time.year, :month => time.month) end |
.reportable_months(options = {}) ⇒ Array<MonthRange>
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 MonthRanges from the given start to the current month.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/double_entry/reporting/month_range.rb', line 20 def reportable_months( = {}) month = [:from] ? from_time([:from]) : earliest_month last = current [month].tap do |months| while month != last month = month.next months << month 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.
76 77 78 |
# File 'lib/double_entry/reporting/month_range.rb', line 76 def <=>(other) start <=> other.start end |
#==(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.
80 81 82 83 |
# File 'lib/double_entry/reporting/month_range.rb', line 80 def ==(other) month == other.month && 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.
85 86 87 |
# File 'lib/double_entry/reporting/month_range.rb', line 85 def all_time MonthRange.new(:year => year, :month => month, :range_type => :all_time) end |
#beginning_of_financial_year ⇒ 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.
68 69 70 71 72 |
# File 'lib/double_entry/reporting/month_range.rb', line 68 def beginning_of_financial_year first_month_of_financial_year = Reporting.configuration.first_month_of_financial_year year = (month >= first_month_of_financial_year) ? @year : (@year - 1) MonthRange.new(:year => year, :month => first_month_of_financial_year) end |
#next ⇒ Object Also known as: succ
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.
60 61 62 63 64 65 66 |
# File 'lib/double_entry/reporting/month_range.rb', line 60 def next if month >= 12 MonthRange.new :year => year + 1, :month => 1 else MonthRange.new :year => year, :month => month + 1 end 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.
52 53 54 55 56 57 58 |
# File 'lib/double_entry/reporting/month_range.rb', line 52 def previous if month <= 1 MonthRange.new :year => year - 1, :month => 12 else MonthRange.new :year => year, :month => month - 1 end 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.
89 90 91 |
# File 'lib/double_entry/reporting/month_range.rb', line 89 def to_s start.strftime('%Y, %b') end |