module FiscallyGemMethods

Public Instance Methods

all_quarter_months() click to toggle source
# File lib/fiscally/fiscally.rb, line 18
def all_quarter_months
  quarters = []
  this_quarter = []
  this_month = fiscal_start
  (1..12).each do |n|
    this_quarter << this_month
    if n % 3 == 0
      quarters << this_quarter
      this_quarter = []
    end
    this_month = this_month < 12 ? this_month + 1 : 1
  end
  quarters
end
Also aliased as: fiscal_calendar
beginning_of_fiscal_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 66
def beginning_of_fiscal_quarter
  self.class.new _last_fiscal_year_for_month(first_month_of_quarter), first_month_of_quarter
end
beginning_of_fiscal_year() click to toggle source
# File lib/fiscally/fiscally.rb, line 62
def beginning_of_fiscal_year
  self.class.new _last_fiscal_year_for_month(q1[0]), q1[0]
end
end_of_fiscal_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 80
def end_of_fiscal_quarter
  if self.class.name == 'Time'
    d = beginning_of_fiscal_quarter + (60*60*24*100)
    self.class.new(d.year, d.month) - (60*60*24)
  else
    d = beginning_of_fiscal_quarter >> 3
    self.class.new(d.year, d.month) - 1
  end
end
end_of_fiscal_year() click to toggle source
# File lib/fiscally/fiscally.rb, line 70
def end_of_fiscal_year
  if self.class.name == 'Time'
    d = beginning_of_fiscal_year + (60*60*24*385)
    self.class.new(d.year, d.month) - (60*60*24)
  else
    d = beginning_of_fiscal_year >> 12
    self.class.new(d.year, d.month) - 1
  end
end
first_month_of_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 38
def first_month_of_quarter
  fiscal_quarter_months[0]
end
first_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 42
def first_quarter
  all_quarter_months[0]
end
Also aliased as: q1
fiscal_calendar()
Alias for: all_quarter_months
fiscal_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 14
def fiscal_quarter
  ((( self.month + ( 12 - fiscal_start ) ) / 3 ) % 4 ) + 1
end
fiscal_quarter_months() click to toggle source
# File lib/fiscally/fiscally.rb, line 34
def fiscal_quarter_months
  all_quarter_months[fiscal_quarter - 1]
end
fiscal_start() click to toggle source
# File lib/fiscally/fiscally.rb, line 5
def fiscal_start
  @fiscal_start = 1 if @fiscal_start.nil?
  @fiscal_start
end
fiscal_start=(month) click to toggle source
# File lib/fiscally/fiscally.rb, line 10
def fiscal_start=(month)
  @fiscal_start = Integer(month)
end
fourth_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 57
def fourth_quarter
  all_quarter_months[3]
end
Also aliased as: q4
q1()
Alias for: first_quarter
q2()
Alias for: second_quarter
q3()
Alias for: third_quarter
q4()
Alias for: fourth_quarter
quarter_ending_dates() click to toggle source
# File lib/fiscally/fiscally.rb, line 99
def quarter_ending_dates
  ret = []
  all_quarter_months.map { |months| months[2] }.each do |m|
    y = m >= fiscal_start ? starting_year : starting_year + 1
    if self.class.name == 'Time'
      d = self.class.new(y, m) + (60*60*24*42)
      ret << self.class.new(d.year, d.month) - (60*60*24)
    else
      d = self.class.new(y, m) >> 1
      ret << self.class.new(d.year, d.month) - 1
    end
  end
  ret
end
quarter_starting_dates() click to toggle source
# File lib/fiscally/fiscally.rb, line 90
def quarter_starting_dates
  ret = []
  all_quarter_months.map { |months| months[0] }.each do |m|
    y = m >= fiscal_start ? starting_year : starting_year + 1
    ret << self.class.new(y, m)
  end
  ret
end
second_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 47
def second_quarter
  all_quarter_months[1]
end
Also aliased as: q2
third_quarter() click to toggle source
# File lib/fiscally/fiscally.rb, line 52
def third_quarter
  all_quarter_months[2]
end
Also aliased as: q3

Protected Instance Methods

_last_fiscal_year_for_month(month) click to toggle source
# File lib/fiscally/fiscally.rb, line 120
def _last_fiscal_year_for_month(month)
  if month == fiscal_start && month == self.month
    self.year
  else
    month >= fiscal_start ? self.year - 1 : self.year
  end
end
starting_year() click to toggle source
# File lib/fiscally/fiscally.rb, line 116
def starting_year
  fiscal_start > 1 ? self.year - 1 : self.year
end