Sha256: d786836e79cc6025a803204b2de741c892347fcb09998605e5a8a7b324c3a277

Contents?: true

Size: 703 Bytes

Versions: 3

Compression:

Stored size: 703 Bytes

Contents

module VRBO
  class Availability

    attr_accessor :start_at, :duration, :error, :dates

    # assumes dates are in ascending order
    def initialize(the_dates = nil)
      @dates = the_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 = count_continuous_dates
    end

    def count_continuous_dates
      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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vrbo-1.0.0 lib/vrbo/availability.rb
vrbo-0.2.1 lib/vrbo/availability.rb
vrbo-0.2.0 lib/vrbo/availability.rb