Class: Quarter
- Inherits:
-
Object
- Object
- Quarter
- Defined in:
- lib/quarter_time/quarter.rb
Instance Attribute Summary collapse
-
#quarter ⇒ Object
Returns the value of attribute quarter.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #date_hash ⇒ Object
- #date_strings_hash ⇒ Object
- #end_date ⇒ Object
- #eql?(other_quarter) ⇒ Boolean (also: #==)
-
#initialize(year, quarter) ⇒ Quarter
constructor
A new instance of Quarter.
- #next ⇒ Object
- #previous ⇒ Object
- #quarter_stamp ⇒ Object
- #start_date ⇒ Object
- #yq_hash ⇒ Object
Constructor Details
#initialize(year, quarter) ⇒ Quarter
Returns a new instance of Quarter.
5 6 7 8 |
# File 'lib/quarter_time/quarter.rb', line 5 def initialize(year,quarter) @year = year.to_i @quarter = quarter.to_i end |
Instance Attribute Details
#quarter ⇒ Object
Returns the value of attribute quarter.
3 4 5 |
# File 'lib/quarter_time/quarter.rb', line 3 def quarter @quarter end |
#year ⇒ Object
Returns the value of attribute year.
2 3 4 |
# File 'lib/quarter_time/quarter.rb', line 2 def year @year end |
Instance Method Details
#date_hash ⇒ Object
32 33 34 |
# File 'lib/quarter_time/quarter.rb', line 32 def date_hash {:start_date=>self.start_date,:end_date=>self.end_date} end |
#date_strings_hash ⇒ Object
36 37 38 |
# File 'lib/quarter_time/quarter.rb', line 36 def date_strings_hash {:start_date=>self.start_date.strftime("%m/%d/%Y"),:end_date=>self.end_date.strftime("%m/%d/%Y")} end |
#end_date ⇒ Object
23 24 25 26 |
# File 'lib/quarter_time/quarter.rb', line 23 def end_date return @_end_date if @_end_date @_end_date = Date.civil(year,(quarter*3),-1) end |
#eql?(other_quarter) ⇒ Boolean Also known as: ==
44 45 46 |
# File 'lib/quarter_time/quarter.rb', line 44 def eql?(other_quarter) other_quarter.class.eql?(self.class) and other_quarter.year == year and other_quarter.quarter == self.quarter end |
#next ⇒ Object
10 11 12 |
# File 'lib/quarter_time/quarter.rb', line 10 def next @next ||= build_next end |
#previous ⇒ Object
14 15 16 |
# File 'lib/quarter_time/quarter.rb', line 14 def previous @previous ||= build_previous end |
#quarter_stamp ⇒ Object
40 41 42 |
# File 'lib/quarter_time/quarter.rb', line 40 def quarter_stamp "Q#{self.quarter}, #{self.year}" end |
#start_date ⇒ Object
18 19 20 21 |
# File 'lib/quarter_time/quarter.rb', line 18 def start_date return @_start_date if @_start_date @_start_date = Date.civil(year,(quarter * 3) - 2) end |
#yq_hash ⇒ Object
28 29 30 |
# File 'lib/quarter_time/quarter.rb', line 28 def yq_hash {:year=>self.year,:quarter=>self.quarter} end |