Class: Tempora::Month
Instance Attribute Summary collapse
Attributes inherited from TimePeriod
#end_date, #start_date
Instance Method Summary
collapse
from, now
Methods included from HasWeeks
#each_week, #weeks
Methods inherited from TimePeriod
#<=>, #contains?, #duration, #hash, #intersection, #overlaps?, #range, #shift
Methods included from HasTime
#end_time, #start_time
Methods included from HasDays
#days, #each_day
Constructor Details
#initialize(year, month) ⇒ Month
Returns a new instance of Month.
12
13
14
15
16
17
18
|
# File 'lib/month.rb', line 12
def initialize(year, month)
@year = Integer(year)
@number = Integer(month).clamp(1, 12)
@start_date = Date.new(@year, @number, 1)
@end_date = Date.new(@year, @number, -1)
end
|
Instance Attribute Details
#number ⇒ Object
Also known as:
month
Returns the value of attribute number.
10
11
12
|
# File 'lib/month.rb', line 10
def number
@number
end
|
#year ⇒ Object
Returns the value of attribute year.
10
11
12
|
# File 'lib/month.rb', line 10
def year
@year
end
|
Instance Method Details
#id(seperator = "-") ⇒ Object
20
21
22
|
# File 'lib/month.rb', line 20
def id(seperator="-")
"#{year}#{seperator}#{number.to_s.rjust(2, '0')}"
end
|
#month_abbr ⇒ Object
32
33
34
|
# File 'lib/month.rb', line 32
def month_abbr
I18n.t('date.abbr_month_names')[number]
end
|
#month_name ⇒ Object
28
29
30
|
# File 'lib/month.rb', line 28
def month_name
I18n.t('date.month_names')[number]
end
|
#next ⇒ Object
Also known as:
succ
36
37
38
|
# File 'lib/month.rb', line 36
def next
self.class.from(start_date.next_month)
end
|
#prev ⇒ Object
Also known as:
pred
40
41
42
|
# File 'lib/month.rb', line 40
def prev
self.class.from(start_date.prev_month)
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/month.rb', line 24
def to_s
"#{month_name} #{year}"
end
|