Class: Tempora::Quarter
- Inherits:
-
TimePeriod
- Object
- TimePeriod
- Tempora::Quarter
- Extended by:
- Initialization
- Defined in:
- lib/quarter.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes inherited from TimePeriod
Instance Method Summary collapse
- #id(seperator = "-") ⇒ Object
-
#initialize(year, quarter) ⇒ Quarter
constructor
A new instance of Quarter.
- #next ⇒ Object (also: #succ)
- #prev ⇒ Object (also: #pred)
- #to_s ⇒ Object
Methods included from Initialization
Methods included from HasWeeks
Methods included from HasMonths
Methods inherited from TimePeriod
#<=>, #contains?, #duration, #hash, #intersection, #overlaps?, #range, #shift
Methods included from HasTime
Methods included from HasDays
Constructor Details
#initialize(year, quarter) ⇒ Quarter
Returns a new instance of Quarter.
14 15 16 17 18 19 20 21 |
# File 'lib/quarter.rb', line 14 def initialize(year, quarter) @year = Integer(year) @number = Integer(quarter).clamp(1,4) start_month = (quarter - 1) * 3 + 1 @start_date = Date.new(year, start_month, 1) @end_date = @start_date.next_month(3).prev_day end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
12 13 14 |
# File 'lib/quarter.rb', line 12 def number @number end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
12 13 14 |
# File 'lib/quarter.rb', line 12 def year @year end |
Instance Method Details
#id(seperator = "-") ⇒ Object
23 24 25 |
# File 'lib/quarter.rb', line 23 def id(seperator="-") "#{year}#{seperator}Q#{number}" end |
#next ⇒ Object Also known as: succ
31 32 33 |
# File 'lib/quarter.rb', line 31 def next self.class.from(start_date >> 3) end |
#prev ⇒ Object Also known as: pred
35 36 37 |
# File 'lib/quarter.rb', line 35 def prev self.class.from(start_date << 3) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/quarter.rb', line 27 def to_s "#{I18n.t('timeperiod.quarter')} #{number}, #{year}" end |