vrbo 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 596c40a43f5f45a2db4e77d00d87e71a1f1adb16
4
- data.tar.gz: abda5349969d9d0e1a3ed9be91cda2d8e5a6d2ad
3
+ metadata.gz: 9a9ee349fb47a9b37f3cd5b3b78fd0426a10a938
4
+ data.tar.gz: 8e02ecf2792dfd8c38348ea248a16619476afc95
5
5
  SHA512:
6
- metadata.gz: 6014064b60cc0d56e8b1bf7ab7d7ab191634cdd5537b287d8885d56349f084d13d4b890ccc958bff4a38e4b8be70518444a866aa883b886557619e1f52fb1ae9
7
- data.tar.gz: 51141db8461e8ce10870e6dc6e7d7db786cd0fae032b7427fd33072989e9dc633ad1bcb649ad443d829500535240172e0ed635edc57861113fd65d5d12158f79
6
+ metadata.gz: f04f9e38b094c1dbd827be4bb9b06b29e55c16956bcc9c6cb7c2c271b5313ee2c7f276a22d8cf7494fad9e1c63aa266039e02dc98b5a7e10952fc5a3e22083ef
7
+ data.tar.gz: 2957e0c4a7da8f0162b3ad3c2042f57315e82dad981af84eca91e24403bec46d2b2abb9d64aeea5ce6c25b66d5d667085ccde55d44d866928b9c60ab3ed3d037
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # Vrbo
1
+ # VRBO Calendar Scraper
2
2
 
3
- TODO: Write a gem description
3
+ Uses mechanize to scrape a VRBO calendar and return a list of available dates. For instance, the gem can
4
+ scrape this calendar: [http://www.vrbo.com/293021/calendar](http://www.vrbo.com/293021/calendar)
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,23 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ If you're just working with one calendar, then you can specify the VRBO calendar id in an initializer:
23
+
24
+ # config/initializers/vrbo_calendar.rb
25
+
26
+ VRBO.configure do |config|
27
+ config.calendar_id = 293021
28
+ end
29
+
30
+ Then to lookup available dates and see if a date range is available:
31
+
32
+ calendar = VRBO::Calendar.new
33
+ calendar.find_all_available_dates
34
+ calendar.available?(Date.today, Date.tomorrow)
35
+ #=> true/false
36
+
37
+ These two methods are also available as class methods, however `available?` will then need an array of dates
38
+ as the third parameter.
22
39
 
23
40
  ## Contributing
24
41
 
data/lib/vrbo.rb CHANGED
@@ -1,10 +1,9 @@
1
- # external libraries
2
- require 'mechanize'
1
+ require 'date'
3
2
  require 'uri'
4
3
  require 'net/https'
4
+ require 'mechanize'
5
5
 
6
- # our stuff
7
- require "vrbo/version"
6
+ require 'vrbo/version'
8
7
  require 'vrbo/configuration'
9
8
  require 'vrbo/availability'
10
9
  require 'vrbo/calendar'
@@ -1,22 +1,21 @@
1
1
  module VRBO
2
2
  class Availability
3
3
 
4
- attr_accessor :first, :duration, :errors
4
+ attr_accessor :start_at, :duration, :error
5
5
 
6
6
  def initialize(dates = [])
7
- if dates.try(:any?)
8
- self.first = Date.parse(dates.shift)
9
- self.duration = self.calc_duration(dates)
10
- self.errors = []
7
+ dates = dates || []
8
+ if dates.any?
9
+ @start_at = Date.parse(dates.shift)
11
10
  else
12
- self.first = Date.today
13
- self.duration = 1
14
- self.errors = %w[Maybe... But likely there was an error]
11
+ @start_at = Date.today
12
+ @error = 'Maybe... But likely there was an error.'
15
13
  end
14
+ @duration = calc_duration(dates)
16
15
  end
17
16
 
18
17
  def calc_duration(dates)
19
- 1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (first + i.days) == 1 ? 1 : 0 }
18
+ 1 + dates.each_with_index.sum { |the_date, i| Date.parse(the_date) - (start_at + i) == 1 ? 1 : 0 }
20
19
  end
21
20
  end
22
21
  end
data/lib/vrbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VRBO
2
- VERSION = "0.0.5"
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vrbo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley