Sha256: 6ce30f4f4e257a47e2bcd93f3418d3ffcc32be523238e16393c6e619ca97d80a

Contents?: true

Size: 513 Bytes

Versions: 2

Compression:

Stored size: 513 Bytes

Contents

module VRBO
  class Availability

    attr_accessor :start_at, :duration, :error

    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

    def calc_duration(dates)
      1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (start_at + i) == 1 ? 1 : 0 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vrbo-0.1.1 lib/vrbo/availability.rb
vrbo-0.1.0 lib/vrbo/availability.rb