Class: Periods::DateCalculator
- Inherits:
-
Object
- Object
- Periods::DateCalculator
- Defined in:
- lib/periods/date_calculator.rb
Instance Method Summary collapse
- #beginning_of_month ⇒ Object
- #end_of_month ⇒ Object
-
#initialize(date) ⇒ DateCalculator
constructor
A new instance of DateCalculator.
- #split ⇒ Object
- #to_date(str) ⇒ Object
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_month ⇒ Object
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_month ⇒ Object
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 |
#split ⇒ Object
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 |