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.



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



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

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.



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

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.



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

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.



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.

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:



20
21
22
23
24
25
26
27
28
29
# 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

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_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.



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

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



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

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



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_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