Class: VRBO::Availability

Inherits:
Object
  • Object
show all
Defined in:
lib/vrbo/availability.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#durationObject

Returns the value of attribute duration.



4
5
6
# File 'lib/vrbo/availability.rb', line 4

def duration
  @duration
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/vrbo/availability.rb', line 4

def error
  @error
end

#start_atObject

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