Module: FiscallyGemMethods

Defined in:
lib/fiscally/fiscally.rb

Instance Method Summary collapse

Instance Method Details

#all_quarter_monthsObject Also known as: fiscal_calendar



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

#beginning_of_fiscal_quarterObject



66
67
68
# 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_yearObject



62
63
64
# 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_quarterObject



80
81
82
83
84
85
86
87
88
# 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_yearObject



70
71
72
73
74
75
76
77
78
# 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_quarterObject



38
39
40
# File 'lib/fiscally/fiscally.rb', line 38

def first_month_of_quarter
  fiscal_quarter_months[0]
end

#first_quarterObject Also known as: q1



42
43
44
# File 'lib/fiscally/fiscally.rb', line 42

def first_quarter
  all_quarter_months[0]
end

#fiscal_quarterObject



14
15
16
# File 'lib/fiscally/fiscally.rb', line 14

def fiscal_quarter
  ((( self.month + ( 12 - fiscal_start ) ) / 3 ) % 4 ) + 1
end

#fiscal_quarter_monthsObject



34
35
36
# File 'lib/fiscally/fiscally.rb', line 34

def fiscal_quarter_months
  all_quarter_months[fiscal_quarter - 1]
end

#fiscal_startObject



5
6
7
8
# File 'lib/fiscally/fiscally.rb', line 5

def fiscal_start
  @fiscal_start = 1 if @fiscal_start.nil?
  @fiscal_start
end

#fiscal_start=(month) ⇒ Object



10
11
12
# File 'lib/fiscally/fiscally.rb', line 10

def fiscal_start=(month)
  @fiscal_start = Integer(month)
end

#fourth_quarterObject Also known as: q4



57
58
59
# File 'lib/fiscally/fiscally.rb', line 57

def fourth_quarter
  all_quarter_months[3]
end

#quarter_ending_datesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 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_datesObject



90
91
92
93
94
95
96
97
# 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_quarterObject Also known as: q2



47
48
49
# File 'lib/fiscally/fiscally.rb', line 47

def second_quarter
  all_quarter_months[1]
end

#third_quarterObject Also known as: q3



52
53
54
# File 'lib/fiscally/fiscally.rb', line 52

def third_quarter
  all_quarter_months[2]
end