class LonelyPlanetScrape::LonelyPlanetTours

Constants

CARD_CONTENT_XPATH
CARD_LOCATION_XPATH
CARD_PRICE_AMOUNT_XPATH
CARD_PRICE_CURRENCY_XPATH
CARD_TITLE_XPATH
LONELYPLANET_URL
TOUR_RELATIVE_DIR
TOUR_XPATH_CARD

Public Class Methods

new() click to toggle source
# File lib/taiwan_tours/lonelyplanet_scrap.rb, line 20
def initialize
  parse_html
end

Public Instance Methods

tours() click to toggle source
# File lib/taiwan_tours/lonelyplanet_scrap.rb, line 24
def tours
  @tours ||= extract_tours
end

Private Instance Methods

extract_tours() click to toggle source
# File lib/taiwan_tours/lonelyplanet_scrap.rb, line 35
def extract_tours
  result = []
  @document.xpath(TOUR_XPATH_CARD).map do |card|
    element = {}
    element['img'] = card.xpath(CARD_IMGLINK_XPATH).text
    element['title'] = card.xpath(CARD_TITLE_XPATH).text.strip
    element['content'] = card.xpath(CARD_CONTENT_XPATH).text.strip
    element['location'] = card.xpath(CARD_LOCATION_XPATH).text
    element['price_currency'] = card.xpath(CARD_PRICE_CURRENCY_XPATH).text
    element['price'] = card.xpath(CARD_PRICE_AMOUNT_XPATH).text
    result << element
  end
  result.to_json
end
parse_html() click to toggle source
# File lib/taiwan_tours/lonelyplanet_scrap.rb, line 30
def parse_html
  url = "#{LONELYPLANET_URL}/#{TOUR_RELATIVE_DIR}"
  @document = Oga.parse_html(open(url))
end