require 'wombat'

module AvoidMetreon
  # Crawls the current event list for Moscone Center in San Francisco, CA
  class MosconeEventCrawler
    include Wombat::Crawler

    base_url 'http://www.moscone.com/site/do/event/list'

    items 'xpath=//table[@id=\'list\']/tr[td+td+td+td]', :iterator do
      start_date xpath: 'td[1]' do |d|
        Date.strptime(d.split(' - ').first, '%m/%d/%y')
      end
      end_date xpath: 'td[1]' do |d|
        Date.strptime(d.split(' - ').last, '%m/%d/%y')
      end
      name xpath: 'td[2]/a'
      url xpath: 'td[2]/a/@href' do |path|
        "http://www.moscone.com#{path}"
      end
    end
  end
end

require 'wombat'

module AvoidMetreon
  # Crawls the current event list for Moscone Center in San Francisco, CA
  class MosconeEventCrawler
    include Wombat::Crawler

    base_url 'http://www.moscone.com/site/do/event/list'

    items 'xpath=//table[@id=\'list\']/tr[td[4]]', :iterator do
      start_date xpath: 'td[1]' do |d|
        Date.strptime(d.split(' - ').first, '%m/%d/%y')
      end
      end_date xpath: 'td[1]' do |d|
        Date.strptime(d.split(' - ').last, '%m/%d/%y')
      end
      name xpath: 'td[2]/a'
      url xpath: 'td[2]/a/@href' do |path|
        "http://www.moscone.com#{path}"
      end
    end
  end
end

Fix selector for calendar rows.
Fix selector for calendar rows.

The + symbol isn't actually supported in XPath. By using it, the event
crawler was always matching 0 elements. Instead, you can select an
element and specify its position within its parent element.
