Class: MonthWeeks::Week
- Inherits:
-
Object
- Object
- MonthWeeks::Week
- Defined in:
- lib/month_weeks/week.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Instance Method Summary collapse
- #dates ⇒ Object
-
#initialize(start_date, end_date) ⇒ Week
constructor
A new instance of Week.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
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_date ⇒ Object (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_date ⇒ Object (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
#dates ⇒ Object
11 12 13 |
# File 'lib/month_weeks/week.rb', line 11 def dates @dates ||= start_date.step(end_date).to_a end |
#to_h ⇒ Object
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_s ⇒ Object
23 24 25 |
# File 'lib/month_weeks/week.rb', line 23 def to_s "#{start_date.strftime} -- #{end_date.strftime}" end |