Class: DoubleEntry::Reporting::MonthRange Private

Inherits:
TimeRange
  • Object
show all
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

Attributes inherited from TimeRange

#day, #finish, #hour, #range_type, #start, #week

Class Method Summary collapse

Instance Method Summary collapse

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.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/double_entry/reporting/month_range.rb', line 39

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

Instance Attribute Details

#monthObject (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.



37
38
39
# File 'lib/double_entry/reporting/month_range.rb', line 37

def month
  @month
end

#yearObject (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.



37
38
39
# File 'lib/double_entry/reporting/month_range.rb', line 37

def year
  @year
end

Class Method Details

.currentObject

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.



11
12
13
# File 'lib/double_entry/reporting/month_range.rb', line 11

def current
  from_time(Time.now)
end

.earliest_monthObject

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.



32
33
34
# File 'lib/double_entry/reporting/month_range.rb', line 32

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.



7
8
9
# File 'lib/double_entry/reporting/month_range.rb', line 7

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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :from (Time)

    Time of the first in the returned sequence of MonthRanges.

Returns:



21
22
23
24
25
26
27
28
29
30
# File 'lib/double_entry/reporting/month_range.rb', line 21

def reportable_months(options = {})
  month = options[:from] ? from_time(options[:from]) : earliest_month
  last = self.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.



77
78
79
# File 'lib/double_entry/reporting/month_range.rb', line 77

def <=>(other)
  self.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.



81
82
83
# File 'lib/double_entry/reporting/month_range.rb', line 81

def ==(other)
  (self.month == other.month) and (self.year == other.year)
end

#all_timeObject

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_yearObject

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.



69
70
71
72
73
# File 'lib/double_entry/reporting/month_range.rb', line 69

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

#nextObject 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.



61
62
63
64
65
66
67
# File 'lib/double_entry/reporting/month_range.rb', line 61

def next
  if month >= 12
    MonthRange.new :year => year + 1, :month => 1
  else
    MonthRange.new :year => year, :month => month + 1
  end
end

#previousObject

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.



53
54
55
56
57
58
59
# File 'lib/double_entry/reporting/month_range.rb', line 53

def previous
  if month <= 1
    MonthRange.new :year => year - 1, :month => 12
  else
    MonthRange.new :year => year, :month => month - 1
  end
end

#to_sObject

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