Class: FiscalYear::Quarter
- Inherits:
-
Object
- Object
- FiscalYear::Quarter
- Defined in:
- lib/fiscal_year/quarter.rb
Class Method Summary collapse
-
.cross_year_in_quarter?(quarter) ⇒ Boolean
True if the quarter is crossed calendar year.
-
.first ⇒ Array<Integer>
The first quarter of the fiscal year.
-
.first?(month) ⇒ Boolean
True if the month is in the first quarter of the fiscal year.
-
.fourth ⇒ Array<Integer>
The fourth quarter of the fiscal year.
-
.fourth?(month) ⇒ Boolean
True if the month is in the fourth quarter of the fiscal year.
-
.months(month) ⇒ Array<Integer>
The quarter months by the month.
-
.passed_month_count_by(date) ⇒ Integer
start by 0.
-
.passed_month_count_by_month(month) ⇒ Integer
start by 0.
-
.quarter_num(month) ⇒ Integer
The quarter number by the month.
-
.range_by(date) ⇒ Range<Date>
The range of the quarter by the date.
-
.second ⇒ Array<Integer>
The second quarter of the fiscal year.
-
.second?(month) ⇒ Boolean
True if the month is in the second quarter of the fiscal year.
-
.third ⇒ Array<Integer>
The third quarter of the fiscal year.
-
.third?(month) ⇒ Boolean
True if the month is in the third quarter of the fiscal year.
Class Method Details
.cross_year_in_quarter?(quarter) ⇒ Boolean
Returns true if the quarter is crossed calendar year.
73 74 75 |
# File 'lib/fiscal_year/quarter.rb', line 73 def cross_year_in_quarter?(quarter) FiscalYear.cross_year? && quarter.any? { |month| month == 12 } end |
.first ⇒ Array<Integer>
Returns the first quarter of the fiscal year.
|
# File 'lib/fiscal_year/quarter.rb', line 6
|
.first?(month) ⇒ Boolean
Returns true if the month is in the first quarter of the fiscal year.
25 26 27 |
# File 'lib/fiscal_year/quarter.rb', line 25 def first?(month) FiscalYear.quarters.first.include?(month) end |
.fourth ⇒ Array<Integer>
Returns the fourth quarter of the fiscal year.
17 18 19 20 21 |
# File 'lib/fiscal_year/quarter.rb', line 17 %i[first second third fourth].each do |method_name| define_method(method_name) do FiscalYear.quarters.public_send(method_name) end end |
.fourth?(month) ⇒ Boolean
Returns true if the month is in the fourth quarter of the fiscal year.
43 44 45 |
# File 'lib/fiscal_year/quarter.rb', line 43 def fourth?(month) FiscalYear.quarters.fourth.include?(month) end |
.months(month) ⇒ Array<Integer>
Returns the quarter months by the month.
49 50 51 |
# File 'lib/fiscal_year/quarter.rb', line 49 def months(month) FiscalYear.quarters.find { |a| a.include?(month) } || raise(StandardError) end |
.passed_month_count_by(date) ⇒ Integer
start by 0.
81 82 83 |
# File 'lib/fiscal_year/quarter.rb', line 81 def passed_month_count_by(date) passed_month_count_by_month(date.month) end |
.passed_month_count_by_month(month) ⇒ Integer
start by 0.
89 90 91 |
# File 'lib/fiscal_year/quarter.rb', line 89 def passed_month_count_by_month(month) months(month).find_index(month) || raise(StandardError) end |
.quarter_num(month) ⇒ Integer
Returns the quarter number by the month.
65 66 67 68 69 |
# File 'lib/fiscal_year/quarter.rb', line 65 def quarter_num(month) rindex = FiscalYear.quarters.rindex(months(month)) rindex.nil? ? 0 : (rindex + 1) end |
.range_by(date) ⇒ Range<Date>
Returns the range of the quarter by the date.
55 56 57 58 59 60 61 |
# File 'lib/fiscal_year/quarter.rb', line 55 def range_by(date) year = date.year this_quarter = months(date.month) last_year = cross_year_in_quarter?(this_quarter) ? year + 1 : year Date.parse("#{year}/#{this_quarter.first}/01")..Date.parse("#{last_year}/#{this_quarter.last}/01").end_of_month end |
.second ⇒ Array<Integer>
Returns the second quarter of the fiscal year.
|
# File 'lib/fiscal_year/quarter.rb', line 9
|
.second?(month) ⇒ Boolean
Returns true if the month is in the second quarter of the fiscal year.
31 32 33 |
# File 'lib/fiscal_year/quarter.rb', line 31 def second?(month) FiscalYear.quarters.second.include?(month) end |
.third ⇒ Array<Integer>
Returns the third quarter of the fiscal year.
|
# File 'lib/fiscal_year/quarter.rb', line 12
|
.third?(month) ⇒ Boolean
Returns true if the month is in the third quarter of the fiscal year.
37 38 39 |
# File 'lib/fiscal_year/quarter.rb', line 37 def third?(month) FiscalYear.quarters.third.include?(month) end |