Module: Periods::Modules::Month::InstanceMethods

Defined in:
lib/periods/modules/month.rb

Instance Method Summary collapse

Instance Method Details

#initialize(date) ⇒ Object



24
25
26
27
28
# File 'lib/periods/modules/month.rb', line 24

def initialize(date)
  date = Date.parse(date.to_s)
  @start_date = beginning_of_month(date)
  @end_date   = end_of_month(date)
end

#monthObject Also known as: number



30
31
32
# File 'lib/periods/modules/month.rb', line 30

def month
  start_date.month
end

#to_s(*args) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/periods/modules/month.rb', line 40

def to_s(*args)
  if args.first.to_s == 'date'
    "#{start_date.strftime("%m.%Y")} (#{start_date.strftime("%d.%m.%Y")} - #{end_date.strftime("%d.%m.%Y")})"
  else
    "#{start_date.strftime("%m.%Y")}"
  end
end

#yearObject



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

def year
  start_date.year
end