Class: Month
- Inherits:
-
Object
show all
- Includes:
- Comparable, DateRange
- Defined in:
- lib/funtimes/month.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DateRange
#&, #days, #encompasses, #intersects, #months, #number_of_days_in, #quarters, #same_range_as, #weeks, #|
Constructor Details
#initialize(month, year) ⇒ Month
Returns a new instance of Month.
13
14
15
16
17
|
# File 'lib/funtimes/month.rb', line 13
def initialize(month, year)
@number, @year = month, year
@start_date = DateTime.new(@year, @number, 1)
@end_date = DateTime.new(next_months_start.year, next_months_start.month, 1) - 1
end
|
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
7
8
9
|
# File 'lib/funtimes/month.rb', line 7
def end_date
@end_date
end
|
#number ⇒ Object
Returns the value of attribute number.
7
8
9
|
# File 'lib/funtimes/month.rb', line 7
def number
@number
end
|
#start_date ⇒ Object
Returns the value of attribute start_date.
7
8
9
|
# File 'lib/funtimes/month.rb', line 7
def start_date
@start_date
end
|
#year ⇒ Object
Returns the value of attribute year.
7
8
9
|
# File 'lib/funtimes/month.rb', line 7
def year
@year
end
|
Class Method Details
.from(date) ⇒ Object
9
10
11
|
# File 'lib/funtimes/month.rb', line 9
def self.from(date)
Month.new(date.month, date.year)
end
|
Instance Method Details
#+(amount) ⇒ Object
41
42
43
44
45
|
# File 'lib/funtimes/month.rb', line 41
def + (amount)
rv = self
amount.times {rv = rv.succ}
rv
end
|
#-(amount) ⇒ Object
47
48
49
50
51
|
# File 'lib/funtimes/month.rb', line 47
def -(amount)
rv = self
amount.times {rv = rv.prev}
rv
end
|
#<=>(other) ⇒ Object
27
28
29
30
|
# File 'lib/funtimes/month.rb', line 27
def <=> (other)
return @year <=> other.year unless @year == other.year
@number <=> other.number
end
|
#name ⇒ Object
23
24
25
|
# File 'lib/funtimes/month.rb', line 23
def name
@start_date.strftime("%B")
end
|
#prev ⇒ Object
36
37
38
39
|
# File 'lib/funtimes/month.rb', line 36
def prev
return Month.new(12, @year-1) if (@number == 1)
Month.new @number-1, @year
end
|
#succ ⇒ Object
32
33
34
|
# File 'lib/funtimes/month.rb', line 32
def succ
Month.from next_months_start
end
|
#to_s ⇒ Object
19
20
21
|
# File 'lib/funtimes/month.rb', line 19
def to_s
"#{name} #{@year}"
end
|