Class: VRBO::Availability
- Inherits:
-
Object
- Object
- VRBO::Availability
- Defined in:
- lib/vrbo/availability.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#error ⇒ Object
Returns the value of attribute error.
-
#start_at ⇒ Object
Returns the value of attribute start_at.
Instance Method Summary collapse
- #calc_duration(dates) ⇒ Object
-
#initialize(dates = []) ⇒ Availability
constructor
A new instance of Availability.
Constructor Details
#initialize(dates = []) ⇒ Availability
Returns a new instance of Availability.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vrbo/availability.rb', line 6 def initialize(dates = []) dates = dates || [] if dates.any? @start_at = Date.parse(dates.shift) else @start_at = Date.today @error = 'Maybe... But likely there was an error.' end @duration = calc_duration(dates) end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
4 5 6 |
# File 'lib/vrbo/availability.rb', line 4 def duration @duration end |
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/vrbo/availability.rb', line 4 def error @error end |
#start_at ⇒ Object
Returns the value of attribute start_at.
4 5 6 |
# File 'lib/vrbo/availability.rb', line 4 def start_at @start_at end |
Instance Method Details
#calc_duration(dates) ⇒ Object
17 18 19 |
# File 'lib/vrbo/availability.rb', line 17 def calc_duration(dates) 1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (start_at + i) == 1 ? 1 : 0 } end |