Class: FiscalDate
- Inherits:
-
Object
- Object
- FiscalDate
- Includes:
- ArithmeticExt, ComparableExt, DateExt
- Defined in:
- lib/fiscal_date.rb,
lib/fiscal_date/date_ext.rb,
lib/fiscal_date/arithmetic_ext.rb,
lib/fiscal_date/comparable_ext.rb
Defined Under Namespace
Modules: ArithmeticExt, ComparableExt, DateExt Classes: InconsistentCalendar, InvalidQuarter, InvalidYear
Constant Summary collapse
- VALID_QUARTERS =
(1..4)
- VALID_YEARS =
{ min: 1, max: 9999 }
Instance Attribute Summary collapse
-
#quarter ⇒ Object
readonly
Returns the value of attribute quarter.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(year, quarter) ⇒ FiscalDate
constructor
A new instance of FiscalDate.
- #to_s ⇒ Object
Methods included from DateExt
Methods included from ArithmeticExt
Methods included from ComparableExt
Constructor Details
#initialize(year, quarter) ⇒ FiscalDate
Returns a new instance of FiscalDate.
19 20 21 22 23 |
# File 'lib/fiscal_date.rb', line 19 def initialize(year, quarter) @year, @quarter = year.to_i, quarter.to_i raise(InvalidQuarter, "`#{quarter}` is not a valid quarter") unless VALID_QUARTERS.include?(@quarter) raise(InvalidYear, "`#{year}` is not a valid year") unless VALID_YEARS[:min] < @year && VALID_YEARS[:max] > @year end |
Instance Attribute Details
#quarter ⇒ Object (readonly)
Returns the value of attribute quarter.
14 15 16 |
# File 'lib/fiscal_date.rb', line 14 def quarter @quarter end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
14 15 16 |
# File 'lib/fiscal_date.rb', line 14 def year @year end |
Instance Method Details
#hash ⇒ Object
31 32 33 |
# File 'lib/fiscal_date.rb', line 31 def hash to_s.hash end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/fiscal_date.rb', line 25 def to_s "Q#{quarter.to_s} #{year.to_s}" end |