Class: Tempora::Month

Inherits:
TimePeriod show all
Extended by:
Initialization
Includes:
HasWeeks
Defined in:
lib/month.rb

Instance Attribute Summary collapse

Attributes inherited from TimePeriod

#end_date, #start_date

Instance Method Summary collapse

Methods included from Initialization

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

#numberObject (readonly) Also known as: month

Returns the value of attribute number.



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

def number
  @number
end

#yearObject (readonly)

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_abbrObject



32
33
34
# File 'lib/month.rb', line 32

def month_abbr
  I18n.t('date.abbr_month_names')[number]
end

#month_nameObject



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

def month_name
  I18n.t('date.month_names')[number]
end

#nextObject Also known as: succ



36
37
38
# File 'lib/month.rb', line 36

def next
  self.class.from(start_date.next_month) # @start_date >> 1
end

#prevObject Also known as: pred



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

def prev
  self.class.from(start_date.prev_month) # @start_date << 1
end

#to_sObject



24
25
26
# File 'lib/month.rb', line 24

def to_s
  "#{month_name} #{year}"
end