class DoubleEntry::Reporting::MonthRange

Attributes

month[R]
year[R]

Public Class Methods

current() click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 10
def current
  from_time(Time.now)
end
earliest_month() click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 31
def earliest_month
  from_time(Reporting.configuration.start_of_business)
end
from_time(time) click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 6
def from_time(time)
  new(:year => time.year, :month => time.month)
end
new(options = {}) click to toggle source
Calls superclass method
# File lib/double_entry/reporting/month_range.rb, line 38
def initialize(options = {})
  super options

  if options.present?
    @month = options[:month]

    month_start = Time.local(year, options[:month], 1)
    @start = month_start
    @finish = month_start.end_of_month

    @start = MonthRange.earliest_month.start if options[:range_type] == :all_time
  end
end
reportable_months(options = {}) click to toggle source

Obtain a sequence of MonthRanges from the given start to the current month.

@option options :from [Time] Time of the first in the returned sequence

of MonthRanges.

@return [Array<MonthRange>]

# File lib/double_entry/reporting/month_range.rb, line 20
def reportable_months(options = {})
  month = options[:from] ? from_time(options[:from]) : earliest_month
  last = current
  [month].tap do |months|
    while month != last
      month = month.next
      months << month
    end
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 76
def <=>(other)
  start <=> other.start
end
==(other) click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 80
def ==(other)
  month == other.month &&
    year == other.year
end
all_time() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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
Also aliased as: succ
previous() click to toggle source
# 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
succ()
Alias for: next
to_s() click to toggle source
# File lib/double_entry/reporting/month_range.rb, line 89
def to_s
  start.strftime('%Y, %b')
end