Class: VRBO::Availability
- Inherits:
-
Object
- Object
- VRBO::Availability
- Defined in:
- lib/vrbo/availability.rb
Instance Attribute Summary collapse
-
#dates ⇒ Object
readonly
Returns the value of attribute dates.
-
#start_at ⇒ Object
readonly
Returns the value of attribute start_at.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(dates = nil) ⇒ Availability
constructor
A new instance of Availability.
Constructor Details
#initialize(dates = nil) ⇒ Availability
Returns a new instance of Availability.
7 8 9 10 11 12 13 14 |
# File 'lib/vrbo/availability.rb', line 7 def initialize(dates = nil) @dates = Array(dates) if @dates.any? @start_at = Date.parse(@dates.shift) else @start_at = Date.today end end |
Instance Attribute Details
#dates ⇒ Object (readonly)
Returns the value of attribute dates.
4 5 6 |
# File 'lib/vrbo/availability.rb', line 4 def dates @dates end |
#start_at ⇒ Object (readonly)
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
#duration ⇒ Object
Note:
assumes @dates are in ascending order
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vrbo/availability.rb', line 17 def duration i = -1 count = 1 dates.each do |the_date| diff = Date.parse(the_date) - (start_at + (i += 1)) if diff.to_i == 1 count += 1 else break end end count end |