Class: Quarter
Constant Summary collapse
- @@months =
[1, 4, 7, 10]
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#number ⇒ Object
Returns the value of attribute number.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(q, y) ⇒ Quarter
constructor
A new instance of Quarter.
- #succ ⇒ Object
- #to_s ⇒ Object
Methods included from DateRange
#&, #days, #encompasses, #intersects, #months, #number_of_days_in, #quarters, #same_range_as, #weeks, #|
Constructor Details
#initialize(q, y) ⇒ Quarter
Returns a new instance of Quarter.
6 7 8 9 10 11 |
# File 'lib/funtimes/quarter.rb', line 6 def initialize(q,y) @number, @year = q, y @start_date = DateTime.new(y, @@months[q-1], 1) @end_date = DateTime.new(y, @@months[q], 1) - 1 unless q == 4 @end_date = DateTime.new(y+1, 1, 1) - 1 if q == 4 end |
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
3 4 5 |
# File 'lib/funtimes/quarter.rb', line 3 def end_date @end_date end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/funtimes/quarter.rb', line 3 def number @number end |
#start_date ⇒ Object
Returns the value of attribute start_date.
3 4 5 |
# File 'lib/funtimes/quarter.rb', line 3 def start_date @start_date end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/funtimes/quarter.rb', line 3 def year @year end |
Class Method Details
.from(date) ⇒ Object
13 14 15 16 |
# File 'lib/funtimes/quarter.rb', line 13 def self.from(date) number = @@months.index(@@months.reverse.detect{|i| i <= date.month}) + 1 new(number, date.year) end |
Instance Method Details
#<=>(other) ⇒ Object
23 24 25 |
# File 'lib/funtimes/quarter.rb', line 23 def <=> (other) @start_date <=> other.start_date end |
#succ ⇒ Object
18 19 20 21 |
# File 'lib/funtimes/quarter.rb', line 18 def succ return Quarter.new(@number+1, @year) unless @number == 4 Quarter.new(1, @year+1) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/funtimes/quarter.rb', line 27 def to_s "Q#{@number}, #{@year}" end |