Class: Periods::DateCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/periods/date_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ DateCalculator

Returns a new instance of DateCalculator.



4
5
6
# File 'lib/periods/date_calculator.rb', line 4

def initialize(date)
  @date = to_date(date)
end

Instance Method Details

#beginning_of_monthObject



8
9
10
11
# File 'lib/periods/date_calculator.rb', line 8

def beginning_of_month
  _, m, y = split
  to_date("#{1}.#{m}.#{y}")
end

#end_of_monthObject



13
14
15
# File 'lib/periods/date_calculator.rb', line 13

def end_of_month
  self.class.new(@date.next_month).beginning_of_month.prev_day
end

#splitObject



17
18
19
# File 'lib/periods/date_calculator.rb', line 17

def split
  @date.strftime('%d.%m.%Y').split('.')
end

#to_date(str) ⇒ Object



21
22
23
# File 'lib/periods/date_calculator.rb', line 21

def to_date(str)
  ::Date.parse(str.to_s)
end