Class: FiscalDate

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from DateExt

included

Methods included from ArithmeticExt

#+, #-

Methods included from ComparableExt

#<=>, included

Constructor Details

#initialize(year, quarter) ⇒ FiscalDate

Returns a new instance of FiscalDate.

Raises:



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

#quarterObject (readonly)

Returns the value of attribute quarter.



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

def quarter
  @quarter
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#hashObject



31
32
33
# File 'lib/fiscal_date.rb', line 31

def hash
  to_s.hash
end

#to_sObject



25
26
27
# File 'lib/fiscal_date.rb', line 25

def to_s
  "Q#{quarter.to_s} #{year.to_s}"
end