Class: Quarter

Inherits:
Object
  • Object
show all
Defined in:
lib/quarter_time/quarter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#quarterObject

Returns the value of attribute quarter.



3
4
5
# File 'lib/quarter_time/quarter.rb', line 3

def quarter
  @quarter
end

#yearObject

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_hashObject



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_hashObject



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_dateObject



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: ==

Returns:

  • (Boolean)


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

#nextObject



10
11
12
# File 'lib/quarter_time/quarter.rb', line 10

def next
  @next ||= build_next
end

#previousObject



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

def previous
  @previous ||= build_previous
end

#quarter_stampObject



40
41
42
# File 'lib/quarter_time/quarter.rb', line 40

def quarter_stamp
  "Q#{self.quarter}, #{self.year}"
end

#start_dateObject



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_hashObject



28
29
30
# File 'lib/quarter_time/quarter.rb', line 28

def yq_hash   
  {:year=>self.year,:quarter=>self.quarter}
end