Class: MonthWeeks::Week

Inherits:
Object
  • Object
show all
Defined in:
lib/month_weeks/week.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date, end_date) ⇒ Week

Returns a new instance of Week.



6
7
8
9
# File 'lib/month_weeks/week.rb', line 6

def initialize(start_date, end_date)
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



5
6
7
# File 'lib/month_weeks/week.rb', line 5

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



5
6
7
# File 'lib/month_weeks/week.rb', line 5

def start_date
  @start_date
end

Instance Method Details

#datesObject



11
12
13
# File 'lib/month_weeks/week.rb', line 11

def dates
  @dates ||= start_date.step(end_date).to_a
end

#to_hObject



15
16
17
# File 'lib/month_weeks/week.rb', line 15

def to_h
   { :start_date => start_date, :end_date => end_date, :dates => dates }
end

#to_json(*args) ⇒ Object



19
20
21
# File 'lib/month_weeks/week.rb', line 19

def to_json(*args)
  self.to_h.to_json(*args)
end

#to_sObject



23
24
25
# File 'lib/month_weeks/week.rb', line 23

def to_s
  "#{start_date.strftime} -- #{end_date.strftime}"
end